diff --git a/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs b/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs index 09940cc78..b22a965fb 100644 --- a/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs +++ b/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs @@ -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 = ""; diff --git a/Duplicati/Library/Backend/Backblaze/B2.cs b/Duplicati/Library/Backend/Backblaze/B2.cs index 1ca5ed2e1..b6808b809 100644 --- a/Duplicati/Library/Backend/Backblaze/B2.cs +++ b/Duplicati/Library/Backend/Backblaze/B2.cs @@ -276,11 +276,7 @@ namespace Duplicati.Library.Backend.Backblaze } finally { - try - { - tmp?.Dispose(); - } - catch { } + tmp?.Dispose(); } } diff --git a/Duplicati/Library/Backend/Dropbox/DropboxHelper.cs b/Duplicati/Library/Backend/Dropbox/DropboxHelper.cs index dd3dc0a11..451bd3d20 100644 --- a/Duplicati/Library/Backend/Dropbox/DropboxHelper.cs +++ b/Duplicati/Library/Backend/Dropbox/DropboxHelper.cs @@ -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 diff --git a/Duplicati/Library/Backend/GoogleServices/GoogleCommon.cs b/Duplicati/Library/Backend/GoogleServices/GoogleCommon.cs index fa7ef0436..5f61530af 100644 --- a/Duplicati/Library/Backend/GoogleServices/GoogleCommon.cs +++ b/Duplicati/Library/Backend/GoogleServices/GoogleCommon.cs @@ -118,7 +118,7 @@ namespace Duplicati.Library.Backend.GoogleServices uploaduri = resp.Headers["Location"]; } - return await ChunkedUploadAsync(oauth, uploaduri, stream, cancelToken); + return await ChunkedUploadAsync(oauth, uploaduri, stream, cancelToken).ConfigureAwait(false); } /// diff --git a/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs b/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs index ba0b7acb6..dbe43c18c 100644 --- a/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs +++ b/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs @@ -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(areq, cancelToken); + return await ReadJSONResponseAsync(areq, cancelToken).ConfigureAwait(false); } /// @@ -280,7 +281,7 @@ namespace Duplicati.Library public virtual async Task ReadJSONResponseAsync(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(resp); } diff --git a/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs b/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs index 95cf218d0..cc368242d 100644 --- a/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs +++ b/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs @@ -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++) diff --git a/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs b/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs index 879b87742..6c9c7555a 100644 --- a/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs +++ b/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs @@ -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)) diff --git a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs index baca40a56..18611030b 100644 --- a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs +++ b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs @@ -88,17 +88,15 @@ namespace Duplicati.Library.Main.Operation.Backup internal class BackendUploader { private static readonly string LOGTAG = Logging.Log.LogTagFromType(); - - private Func m_backendFactory; + private readonly Func 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); diff --git a/Duplicati/Library/Main/Operation/Backup/SpillCollectorProcess.cs b/Duplicati/Library/Main/Operation/Backup/SpillCollectorProcess.cs index 5c9f8650e..2244c707e 100644 --- a/Duplicati/Library/Main/Operation/Backup/SpillCollectorProcess.cs +++ b/Duplicati/Library/Main/Operation/Backup/SpillCollectorProcess.cs @@ -57,10 +57,10 @@ namespace Duplicati.Library.Main.Operation.Backup { var lst = new List(); - 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); } });