From e87688d9d364abf02db0320a497cfad0bbc49e85 Mon Sep 17 00:00:00 2001 From: marodev Date: Sat, 15 May 2021 17:02:57 +0200 Subject: Fix ReSharper's "Use string interpolation expression" / Code Smell --- Duplicati/Library/Backend/Rclone/Rclone.cs | 14 +++++++------- Duplicati/UnitTest/PurgeTesting.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'Duplicati') diff --git a/Duplicati/Library/Backend/Rclone/Rclone.cs b/Duplicati/Library/Backend/Rclone/Rclone.cs index a4bd84fca..024d7e648 100644 --- a/Duplicati/Library/Backend/Rclone/Rclone.cs +++ b/Duplicati/Library/Backend/Rclone/Rclone.cs @@ -103,7 +103,7 @@ namespace Duplicati.Library.Backend ProcessStartInfo psi = new ProcessStartInfo { - Arguments = String.Format("{0} {1}", arguments, opt_rclone), + Arguments = $"{arguments} {opt_rclone}", CreateNoWindow = true, FileName = command, RedirectStandardError = true, @@ -181,7 +181,7 @@ namespace Duplicati.Library.Backend if (errorBuilder.ToString().Contains(RCLONE_ERROR_CONFIG_NOT_FOUND)) { - throw new Exception(String.Format("Missing config file? {0}", errorBuilder)); + throw new Exception($"Missing config file? {errorBuilder}"); } if (errorBuilder.Length > 0) { @@ -199,7 +199,7 @@ namespace Duplicati.Library.Backend try { - str_result = RcloneCommandExecuter(rclone_executable, String.Format("lsjson {0}:{1}", remote_repo, remote_path), CancellationToken.None).Await(); + str_result = RcloneCommandExecuter(rclone_executable, $"lsjson {remote_repo}:{remote_path}", CancellationToken.None).Await(); // this will give an error if the executable does not exist. } @@ -237,7 +237,7 @@ namespace Duplicati.Library.Backend { try { - return RcloneCommandExecuter(rclone_executable, String.Format("copyto {0}:{1} {2}:{3}/{4}", local_repo, filename, remote_repo, remote_path, remotename), cancelToken); + return RcloneCommandExecuter(rclone_executable, $"copyto {local_repo}:{filename} {remote_repo}:{remote_path}/{remotename}", cancelToken); } catch (FolderMissingException ex) { @@ -249,7 +249,7 @@ namespace Duplicati.Library.Backend { try { - RcloneCommandExecuter(rclone_executable, String.Format("copyto {2}:{3} {0}:{1}", local_repo, filename, remote_repo, Path.Combine(this.remote_path, remotename)), CancellationToken.None).Await(); + RcloneCommandExecuter(rclone_executable, $"copyto {local_repo}:{filename} {remote_repo}:{Path.Combine(this.remote_path, remotename)}", CancellationToken.None).Await(); } catch (FolderMissingException ex) { throw new FileMissingException(ex); @@ -262,7 +262,7 @@ namespace Duplicati.Library.Backend // Will give a "directory not found" error if the file does not exist, need to change that to a missing file exception try { - RcloneCommandExecuter(rclone_executable, String.Format("delete {0}:{1}", remote_repo, Path.Combine(remote_path, remotename)), CancellationToken.None).Await(); + RcloneCommandExecuter(rclone_executable, $"delete {remote_repo}:{Path.Combine(remote_path, remotename)}", CancellationToken.None).Await(); } catch (FolderMissingException ex) { throw new FileMissingException(ex); @@ -308,7 +308,7 @@ namespace Duplicati.Library.Backend public void CreateFolder() { - RcloneCommandExecuter(rclone_executable, String.Format("mkdir {0}:{1}", remote_repo, remote_path), CancellationToken.None).Await(); + RcloneCommandExecuter(rclone_executable, $"mkdir {remote_repo}:{remote_path}", CancellationToken.None).Await(); } #endregion diff --git a/Duplicati/UnitTest/PurgeTesting.cs b/Duplicati/UnitTest/PurgeTesting.cs index 97954e5a5..bca73159d 100644 --- a/Duplicati/UnitTest/PurgeTesting.cs +++ b/Duplicati/UnitTest/PurgeTesting.cs @@ -175,9 +175,9 @@ namespace Duplicati.UnitTest Console.WriteLine("Listing final version information"); Console.WriteLine("Versions:"); - Console.WriteLine(" " + string.Join(Environment.NewLine + " ", filesets.Select(x => string.Format("{0}: {1}, {2} {3}", x.Version, x.Time, x.FileCount, x.FileSizes)))); + Console.WriteLine(" " + string.Join(Environment.NewLine + " ", filesets.Select(x => $"{x.Version}: {x.Time}, {x.FileCount} {x.FileSizes}"))); Console.WriteLine("Files:"); - Console.WriteLine(" " + string.Join(Environment.NewLine + " ", files.Select(x => string.Format("{0}: {1}", x.Path, string.Join(" - ", x.Sizes.Select(y => y.ToString())))))); + Console.WriteLine(" " + string.Join(Environment.NewLine + " ", files.Select(x => $"{x.Path}: {string.Join(" - ", x.Sizes.Select(y => y.ToString()))}"))); Assert.AreEqual(4, filesets.Length, "Incorrect number of filesets after final backup"); Assert.AreEqual(filenames.Count + 1, filecount, "Incorrect number of files after final backup"); -- cgit v1.2.3 From 29f1d2c3cbb27ff1c1d205abc7d2f81ed51cb894 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 15 May 2021 14:06:39 -0700 Subject: Fix bug handling deprecated Azure and S3 options. In pull request #4443, we renamed some of the Azure and S3 options to use dashes '-' instead of underscores '_' for consistency. However, our treatment of the options in the backend constructors still required that the underscore versions be present even if the dashed version was provided. Now, we allow for either option to be present, but the value for the dashed version will take precedence. --- Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs | 12 ++++++++---- Duplicati/Library/Backend/S3/S3Backend.cs | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'Duplicati') diff --git a/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs b/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs index 42d6d7725..98822fdbc 100644 --- a/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs +++ b/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs @@ -53,10 +53,14 @@ namespace Duplicati.Library.Backend.AzureBlob storageAccountName = options["auth-username"]; if (options.ContainsKey("auth-password")) accessKey = options["auth-password"]; - if (options.ContainsKey("azure_account_name") || options.ContainsKey("azure-account-name")) - storageAccountName = options["azure_account_name"] ?? options["azure-account-name"]; - if (options.ContainsKey("azure_access_key") || options.ContainsKey("azure-access-key")) - accessKey = options["azure_access_key"] ?? options["azure-access-key"]; + if (options.ContainsKey("azure_account_name")) + storageAccountName = options["azure_account_name"]; + if (options.ContainsKey("azure-account-name")) + storageAccountName = options["azure-account-name"]; + if (options.ContainsKey("azure_access_key")) + accessKey = options["azure_access_key"]; + if (options.ContainsKey("azure-access-key")) + accessKey = options["azure-access-key"]; if (!string.IsNullOrEmpty(uri.Username)) storageAccountName = uri.Username; if (!string.IsNullOrEmpty(uri.Password)) diff --git a/Duplicati/Library/Backend/S3/S3Backend.cs b/Duplicati/Library/Backend/S3/S3Backend.cs index 2470b196d..6b14eabbf 100644 --- a/Duplicati/Library/Backend/S3/S3Backend.cs +++ b/Duplicati/Library/Backend/S3/S3Backend.cs @@ -185,10 +185,14 @@ namespace Duplicati.Library.Backend if (options.ContainsKey("auth-password")) awsKey = options["auth-password"]; - if (options.ContainsKey("aws_access_key_id") || options.ContainsKey("aws-access-key-id")) - awsID = options["aws_access_key_id"] ?? options["aws-access-key-id"]; - if (options.ContainsKey("aws_secret_access_key") || options.ContainsKey("aws-secret-access-key")) - awsKey = options["aws_secret_access_key"] ?? options["aws-secret-access-key"]; + if (options.ContainsKey("aws_access_key_id")) + awsID = options["aws_access_key_id"]; + if (options.ContainsKey("aws-access-key-id")) + awsID = options["aws-access-key-id"]; + if (options.ContainsKey("aws_secret_access_key")) + awsKey = options["aws_secret_access_key"]; + if (options.ContainsKey("aws-secret-access-key")) + awsKey = options["aws-secret-access-key"]; if (!string.IsNullOrEmpty(uri.Username)) awsID = uri.Username; if (!string.IsNullOrEmpty(uri.Password)) -- cgit v1.2.3 From a156c511da185fbf3bfd7fc58276f7ded7e54074 Mon Sep 17 00:00:00 2001 From: marodev Date: Sun, 16 May 2021 09:12:00 +0200 Subject: Reorder parameters of previously wrongly refactored string interpolation --- Duplicati/Library/Backend/Rclone/Rclone.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Duplicati') diff --git a/Duplicati/Library/Backend/Rclone/Rclone.cs b/Duplicati/Library/Backend/Rclone/Rclone.cs index 024d7e648..97804dd58 100644 --- a/Duplicati/Library/Backend/Rclone/Rclone.cs +++ b/Duplicati/Library/Backend/Rclone/Rclone.cs @@ -249,7 +249,7 @@ namespace Duplicati.Library.Backend { try { - RcloneCommandExecuter(rclone_executable, $"copyto {local_repo}:{filename} {remote_repo}:{Path.Combine(this.remote_path, remotename)}", CancellationToken.None).Await(); + RcloneCommandExecuter(rclone_executable, $"copyto {remote_repo}:{Path.Combine(this.remote_path, remotename)} {local_repo}:{filename}", CancellationToken.None).Await(); } catch (FolderMissingException ex) { throw new FileMissingException(ex); -- cgit v1.2.3