From 57c8c025d130e76b772c59f5476f5f0fec578e78 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Fri, 1 Nov 2024 17:01:30 +0100 Subject: [PATCH] This fixes an issues with the recovery tool that would mangle names if no encryption module is set on the source files. This uses a test provided in #4490 to verify. This fixes #4490 --- .../CommandLine/RecoveryTool/Recompress.cs | 2 +- Duplicati/UnitTest/RecoveryToolTests.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Duplicati/CommandLine/RecoveryTool/Recompress.cs b/Duplicati/CommandLine/RecoveryTool/Recompress.cs index cb7f23ceb..422248adb 100644 --- a/Duplicati/CommandLine/RecoveryTool/Recompress.cs +++ b/Duplicati/CommandLine/RecoveryTool/Recompress.cs @@ -218,7 +218,7 @@ namespace Duplicati.CommandLine.RecoveryTool { // Correct inner filename extension to target compression type cmfileNew = cmfileNew.Replace("." + cmFileVolume.CompressionModule, "." + target_compr_module); - if (!reencrypt) + if (!reencrypt && !string.IsNullOrWhiteSpace(cmFileVolume.EncryptionModule)) cmfileNew = cmfileNew.Replace("." + cmFileVolume.EncryptionModule, ""); //Because compression changes blocks file sizes - needs to be updated diff --git a/Duplicati/UnitTest/RecoveryToolTests.cs b/Duplicati/UnitTest/RecoveryToolTests.cs index 53889b1d5..845cf718b 100644 --- a/Duplicati/UnitTest/RecoveryToolTests.cs +++ b/Duplicati/UnitTest/RecoveryToolTests.cs @@ -260,5 +260,40 @@ namespace Duplicati.UnitTest TestUtils.AssertDirectoryTreesAreEquivalent(this.DATAFOLDER, restoreFolder, false, "Verifying restore using RecoveryTool."); } + + [Test] + [Category("RecoveryTool")] + [TestCase(false)] + [TestCase(true)] + public void Recompress(bool noEncryption) + { + // Files to create in MB. + int[] fileSizes = { 10, 20, 30 }; + foreach (int size in fileSizes) + { + byte[] data = new byte[size * 1024 * 1024]; + Random rng = new Random(); + rng.NextBytes(data); + File.WriteAllBytes(Path.Combine(this.DATAFOLDER, size + "MB"), data); + } + // Run a backup. + Dictionary options = new Dictionary(this.TestOptions) + { + ["no-encryption"] = noEncryption.ToString() + }; + string backendURL = "file://" + this.TARGETFOLDER; + using (Controller c = new Controller(backendURL, options, null)) + { + IBackupResults backupResults = c.Backup(new[] { this.DATAFOLDER }); + Assert.AreEqual(0, backupResults.Errors.Count()); + Assert.AreEqual(0, backupResults.Warnings.Count()); + } + // Recompress. + string downloadFolder = Path.Combine(this.RESTOREFOLDER, "downloadedFiles"); + Directory.CreateDirectory(downloadFolder); + int status = CommandLine.RecoveryTool.Program.Main(new[] { "recompress", "zip", $"{backendURL}", this.RESTOREFOLDER, $"--passphrase={options["passphrase"]}" }); + Assert.AreEqual(0, status); + } + } } \ No newline at end of file