Fix several Codacy issues
This commit is contained in:
@@ -310,7 +310,7 @@ namespace Duplicati.Library.Backend.AlternativeFTP
|
||||
public async Task Put(string remotename, Stream input, CancellationToken cancelToken)
|
||||
{
|
||||
string remotePath = remotename;
|
||||
long streamLen = -1;
|
||||
long streamLen;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -320,8 +320,7 @@ namespace Duplicati.Library.Backend.AlternativeFTP
|
||||
{
|
||||
streamLen = input.Length;
|
||||
}
|
||||
// ReSharper disable once EmptyGeneralCatchClause
|
||||
catch { }
|
||||
catch (NotSupportedException) { streamLen = -1; }
|
||||
|
||||
// Get the remote path
|
||||
remotePath = "";
|
||||
|
||||
@@ -276,11 +276,7 @@ namespace Duplicati.Library.Backend.Backblaze
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
tmp?.Dispose();
|
||||
}
|
||||
catch { }
|
||||
tmp?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Duplicati.Library.Backend
|
||||
|
||||
using (var response = GetResponse(areq))
|
||||
using (var sr = new StreamReader(response.GetResponseStream()))
|
||||
await sr.ReadToEndAsync();
|
||||
await sr.ReadToEndAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// finish session and commit
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace Duplicati.Library.Backend.GoogleServices
|
||||
uploaduri = resp.Headers["Location"];
|
||||
}
|
||||
|
||||
return await ChunkedUploadAsync<TResponse>(oauth, uploaduri, stream, cancelToken);
|
||||
return await ChunkedUploadAsync<TResponse>(oauth, uploaduri, stream, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Duplicati.Library
|
||||
return req;
|
||||
}
|
||||
|
||||
private void CreateBoundary(out string boundary, out byte[] bodyterminator)
|
||||
private static void CreateBoundary(out string boundary, out byte[] bodyterminator)
|
||||
{
|
||||
boundary = "----DuplicatiFormBoundary" + Guid.NewGuid().ToString("N");
|
||||
bodyterminator = Encoding.UTF8.GetBytes("--" + boundary + "--");
|
||||
@@ -222,9 +222,10 @@ namespace Duplicati.Library
|
||||
setup?.Invoke(req);
|
||||
|
||||
var areq = new AsyncHttpRequest(req);
|
||||
await setupbodyreq?.Invoke(areq, cancelToken);
|
||||
if (setupbodyreq != null)
|
||||
await setupbodyreq(areq, cancelToken).ConfigureAwait(false);
|
||||
|
||||
return await ReadJSONResponseAsync<T>(areq, cancelToken);
|
||||
return await ReadJSONResponseAsync<T>(areq, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -280,7 +281,7 @@ namespace Duplicati.Library
|
||||
|
||||
public virtual async Task<T> ReadJSONResponseAsync<T>(AsyncHttpRequest req, CancellationToken cancelToken, object requestdata = null)
|
||||
{
|
||||
using (var resp = await GetResponseAsync(req, cancelToken, requestdata))
|
||||
using (var resp = await GetResponseAsync(req, cancelToken, requestdata).ConfigureAwait(false))
|
||||
return ReadJSONResponse<T>(resp);
|
||||
}
|
||||
|
||||
|
||||
@@ -368,7 +368,7 @@ namespace Duplicati.Library.Backend
|
||||
int read = 0;
|
||||
for (int offset = 0; offset < stream.Length; offset += read)
|
||||
{
|
||||
read = await stream.ReadAsync(fragmentBuffer, 0, bufferSize, cancelToken);
|
||||
read = await stream.ReadAsync(fragmentBuffer, 0, bufferSize, cancelToken).ConfigureAwait(false);
|
||||
|
||||
int retryCount = this.fragmentRetryCount;
|
||||
for (int attempt = 0; attempt < retryCount; attempt++)
|
||||
|
||||
@@ -544,12 +544,12 @@ namespace Duplicati.Library.Backend
|
||||
|
||||
useNewContext = true; // disable retry
|
||||
if (!m_useBinaryDirectMode)
|
||||
await uploadFileSlicePerSlice(ctx, remoteFolder, stream, fileurl, cancelToken);
|
||||
await uploadFileSlicePerSlice(ctx, remoteFolder, stream, fileurl, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (ServerException) { throw; /* rethrow if Server answered */ }
|
||||
catch (Interface.FileMissingException) { throw; }
|
||||
catch (Interface.FolderMissingException) { throw; }
|
||||
catch { if (!useNewContext) /* retry */ { await doPut(remotename, stream, true, cancelToken); } else throw; }
|
||||
catch { if (!useNewContext) /* retry */ { await doPut(remotename, stream, true, cancelToken).ConfigureAwait(false); } else throw; }
|
||||
|
||||
if (m_useBinaryDirectMode)
|
||||
{
|
||||
@@ -585,7 +585,7 @@ namespace Duplicati.Library.Backend
|
||||
{
|
||||
int bufCnt = 0;
|
||||
// read chunk to array (necessary because chunk uploads fail if size unknown)
|
||||
while (bufCnt < blockSize && (lastreadsize = await sourceFileStream.ReadAsync(buf, bufCnt, blockSize - bufCnt, cancelToken)) > 0)
|
||||
while (bufCnt < blockSize && (lastreadsize = await sourceFileStream.ReadAsync(buf, bufCnt, blockSize - bufCnt, cancelToken).ConfigureAwait(false)) > 0)
|
||||
bufCnt += lastreadsize;
|
||||
|
||||
using (var contentChunk = new MemoryStream(buf, 0, bufCnt, false))
|
||||
|
||||
@@ -88,17 +88,15 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
internal class BackendUploader
|
||||
{
|
||||
private static readonly string LOGTAG = Logging.Log.LogTagFromType<BackendUploader>();
|
||||
|
||||
private Func<IBackend> m_backendFactory;
|
||||
private readonly Func<IBackend> m_backendFactory;
|
||||
private CancellationTokenSource m_cancelTokenSource;
|
||||
private Options m_options;
|
||||
private ITaskReader m_taskreader;
|
||||
private StatsCollector m_stats;
|
||||
private DatabaseCommon m_database;
|
||||
private readonly Options m_options;
|
||||
private readonly ITaskReader m_taskreader;
|
||||
private readonly StatsCollector m_stats;
|
||||
private readonly DatabaseCommon m_database;
|
||||
private readonly BackupResults m_results;
|
||||
private readonly FileProgressThrottler m_progressUpdater;
|
||||
private string m_lastThrottleUploadValue;
|
||||
private string m_lastThrottleDownloadValue;
|
||||
private int m_maxConcurrentUploads;
|
||||
private long m_initialUploadThrottle;
|
||||
|
||||
@@ -225,7 +223,7 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
});
|
||||
}
|
||||
|
||||
private Exception GetInnerMostException(Exception ex)
|
||||
private static Exception GetInnerMostException(Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null)
|
||||
ex = ex.InnerException;
|
||||
@@ -418,12 +416,6 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
updateThrottleSpeeds = true;
|
||||
}
|
||||
|
||||
m_options.RawOptions.TryGetValue("throttle-download", out tmp);
|
||||
if (tmp != m_lastThrottleDownloadValue)
|
||||
{
|
||||
m_lastThrottleDownloadValue = tmp;
|
||||
}
|
||||
|
||||
if (updateThrottleSpeeds)
|
||||
m_progressUpdater.UpdateThrottleSpeeds(m_options.MaxUploadPrSecond);
|
||||
m_progressUpdater.UpdateFileProgress(path, progress, ts);
|
||||
|
||||
@@ -57,10 +57,10 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
{
|
||||
var lst = new List<SpillVolumeRequest>();
|
||||
|
||||
while (!await self.Input.IsRetiredAsync)
|
||||
while (!await self.Input.IsRetiredAsync.ConfigureAwait(false))
|
||||
try
|
||||
{
|
||||
lst.Add(await self.Input.ReadAsync());
|
||||
lst.Add(await self.Input.ReadAsync().ConfigureAwait(false));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
while (lst.Count > 1)
|
||||
{
|
||||
// We ignore the stop signal, but not the pause and terminate
|
||||
await taskreader.ProgressAsync;
|
||||
await taskreader.ProgressAsync.ConfigureAwait(false);
|
||||
|
||||
SpillVolumeRequest target = null;
|
||||
var source = lst[0];
|
||||
@@ -97,7 +97,7 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
{
|
||||
// No more targets, make one
|
||||
target = new SpillVolumeRequest(new BlockVolumeWriter(options), source.IndexVolume == null ? null : new TemporaryIndexVolume(options));
|
||||
target.BlockVolume.VolumeID = await database.RegisterRemoteVolumeAsync(target.BlockVolume.RemoteFilename, RemoteVolumeType.Blocks, RemoteVolumeState.Temporary);
|
||||
target.BlockVolume.VolumeID = await database.RegisterRemoteVolumeAsync(target.BlockVolume.RemoteFilename, RemoteVolumeType.Blocks, RemoteVolumeState.Temporary).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -114,7 +114,7 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
|
||||
var len = rd.ReadBlock(file.Key, buffer);
|
||||
target.BlockVolume.AddBlock(file.Key, buffer, 0, len, Duplicati.Library.Interface.CompressionHint.Default);
|
||||
await database.MoveBlockToVolumeAsync(file.Key, len, source.BlockVolume.VolumeID, target.BlockVolume.VolumeID);
|
||||
await database.MoveBlockToVolumeAsync(file.Key, len, source.BlockVolume.VolumeID, target.BlockVolume.VolumeID).ConfigureAwait(false);
|
||||
|
||||
if (target.IndexVolume != null)
|
||||
target.IndexVolume.AddBlock(file.Key, len);
|
||||
@@ -122,7 +122,7 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
if (target.BlockVolume.Filesize > options.VolumeSize - options.Blocksize)
|
||||
{
|
||||
target.BlockVolume.Close();
|
||||
await UploadVolumeAndIndex(target, self.Output, options, database);
|
||||
await UploadVolumeAndIndex(target, self.Output, options, database).ConfigureAwait(false);
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
|
||||
// Make sure they are out of the database
|
||||
System.IO.File.Delete(source.BlockVolume.LocalFilename);
|
||||
await database.SafeDeleteRemoteVolumeAsync(source.BlockVolume.RemoteFilename);
|
||||
await database.SafeDeleteRemoteVolumeAsync(source.BlockVolume.RemoteFilename).ConfigureAwait(false);
|
||||
|
||||
// Re-inject the target if it has content
|
||||
if (target != null)
|
||||
@@ -140,10 +140,10 @@ namespace Duplicati.Library.Main.Operation.Backup
|
||||
foreach (var n in lst)
|
||||
{
|
||||
// We ignore the stop signal, but not the pause and terminate
|
||||
await taskreader.ProgressAsync;
|
||||
await taskreader.ProgressAsync.ConfigureAwait(false);
|
||||
|
||||
n.BlockVolume.Close();
|
||||
await UploadVolumeAndIndex(n, self.Output, options, database);
|
||||
await UploadVolumeAndIndex(n, self.Output, options, database).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user