Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Hsu <kennethhsu@gmail.com>2020-08-01 02:29:28 +0300
committerKenneth Hsu <kennethhsu@gmail.com>2020-08-01 02:29:28 +0300
commitd99d40717d37f6fc667a1e5a64135b9161b82327 (patch)
tree80106d0e353020e8c3c14b3dace8203e905ee790 /Duplicati/UnitTest
parent568fadbcec1b524850a797119b60f65cebb9eac8 (diff)
parentdb2235ad17ffb8973233fab88f3d89ce69d99ae9 (diff)
Merge remote-tracking branch 'upstream/master' into test_invalid_windows_paths
This allows us to simplify the ProblematicPathTests because the test teardown methods can now handle deleting directories containing problematic paths.
Diffstat (limited to 'Duplicati/UnitTest')
-rw-r--r--Duplicati/UnitTest/BasicSetupHelper.cs90
-rw-r--r--Duplicati/UnitTest/CommandLineOperationsTests.cs48
-rw-r--r--Duplicati/UnitTest/Duplicati.UnitTest.csproj1
-rw-r--r--Duplicati/UnitTest/ProblematicPathTests.cs257
4 files changed, 199 insertions, 197 deletions
diff --git a/Duplicati/UnitTest/BasicSetupHelper.cs b/Duplicati/UnitTest/BasicSetupHelper.cs
index 891bf727b..ba4b3a353 100644
--- a/Duplicati/UnitTest/BasicSetupHelper.cs
+++ b/Duplicati/UnitTest/BasicSetupHelper.cs
@@ -18,6 +18,9 @@ using System;
using NUnit.Framework;
using System.IO;
using System.Collections.Generic;
+using System.IO.Compression;
+using Duplicati.Library.Common;
+using Duplicati.Library.Common.IO;
namespace Duplicati.UnitTest
{
@@ -61,6 +64,8 @@ namespace Duplicati.UnitTest
/// </summary>
public static readonly bool DEBUG_OUTPUT = Library.Utility.Utility.ParseBool(Environment.GetEnvironmentVariable("DEBUG_OUTPUT"), false);
+ protected static readonly ISystemIO systemIO = SystemIO.IO_OS;
+
/// <summary>
/// Writes a message to TestContext.Progress and Console.Out
/// </summary>
@@ -81,7 +86,7 @@ namespace Duplicati.UnitTest
Console.SetOut(TestContext.Progress);
}
- Directory.CreateDirectory(BASEFOLDER);
+ systemIO.DirectoryCreate(BASEFOLDER);
this.TearDown();
this.OneTimeTearDown();
}
@@ -95,37 +100,37 @@ namespace Duplicati.UnitTest
[SetUp]
public virtual void SetUp()
{
- Directory.CreateDirectory(this.DATAFOLDER);
- Directory.CreateDirectory(this.TARGETFOLDER);
- Directory.CreateDirectory(this.RESTOREFOLDER);
+ systemIO.DirectoryCreate(this.DATAFOLDER);
+ systemIO.DirectoryCreate(this.TARGETFOLDER);
+ systemIO.DirectoryCreate(this.RESTOREFOLDER);
}
[TearDown]
public virtual void TearDown()
{
- if (Directory.Exists(this.DATAFOLDER))
+ if (systemIO.DirectoryExists(this.DATAFOLDER))
{
- Directory.Delete(this.DATAFOLDER, true);
+ systemIO.DirectoryDelete(this.DATAFOLDER, true);
}
- if (Directory.Exists(this.TARGETFOLDER))
+ if (systemIO.DirectoryExists(this.TARGETFOLDER))
{
- Directory.Delete(this.TARGETFOLDER, true);
+ systemIO.DirectoryDelete(this.TARGETFOLDER, true);
}
- if (Directory.Exists(this.RESTOREFOLDER))
+ if (systemIO.DirectoryExists(this.RESTOREFOLDER))
{
- Directory.Delete(this.RESTOREFOLDER, true);
+ systemIO.DirectoryDelete(this.RESTOREFOLDER, true);
}
- if (File.Exists(this.LOGFILE))
+ if (systemIO.FileExists(this.LOGFILE))
{
- File.Delete(this.LOGFILE);
+ systemIO.FileDelete(this.LOGFILE);
}
- if (File.Exists(this.DBFILE))
+ if (systemIO.FileExists(this.DBFILE))
{
- File.Delete(this.DBFILE);
+ systemIO.FileDelete(this.DBFILE);
}
- if (File.Exists($"{this.DBFILE}-journal"))
+ if (systemIO.FileExists($"{this.DBFILE}-journal"))
{
- File.Delete($"{this.DBFILE}-journal");
+ systemIO.FileDelete($"{this.DBFILE}-journal");
}
}
@@ -153,6 +158,59 @@ namespace Duplicati.UnitTest
}
}
+ /// <summary>
+ /// Alternative to System.IO.Compression.ZipFile.ExtractToDirectory()
+ /// that handles long paths.
+ /// </summary>
+ protected static void ZipFileExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName)
+ {
+ if (Platform.IsClientWindows)
+ {
+ // Handle long paths under Windows by extracting to a
+ // temporary file and moving the resulting file to the
+ // actual destination using functions that support
+ // long paths.
+ using (var archive = ZipFile.OpenRead(sourceArchiveFileName))
+ {
+ foreach (var entry in archive.Entries)
+ {
+ // By the ZIP spec, directories end in a forward slash
+ var isDirectory = entry.FullName.EndsWith("/");
+ var destination =
+ systemIO.PathGetFullPath(systemIO.PathCombine(destinationDirectoryName, entry.FullName));
+ if (isDirectory)
+ {
+ systemIO.DirectoryCreate(destination);
+ }
+ else
+ {
+ // Not every directory is recorded separately,
+ // so create directories if needed
+ systemIO.DirectoryCreate(systemIO.PathGetDirectoryName(destination));
+ // Extract file to temporary file, then move to
+ // the (possibly) long path destination
+ var tempFile = Path.GetTempFileName();
+ try
+ {
+ entry.ExtractToFile(tempFile, true);
+ systemIO.FileMove(tempFile, destination);
+ }
+ finally
+ {
+ if (systemIO.FileExists(tempFile))
+ {
+ systemIO.FileDelete(tempFile);
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ ZipFile.ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName);
+ }
+ }
}
}
diff --git a/Duplicati/UnitTest/CommandLineOperationsTests.cs b/Duplicati/UnitTest/CommandLineOperationsTests.cs
index 9bb0b1927..cb7bebc8c 100644
--- a/Duplicati/UnitTest/CommandLineOperationsTests.cs
+++ b/Duplicati/UnitTest/CommandLineOperationsTests.cs
@@ -48,7 +48,7 @@ namespace Duplicati.UnitTest
get
{
return
- from x in Directory.EnumerateDirectories(SOURCEFOLDER)
+ from x in systemIO.EnumerateDirectories(SOURCEFOLDER)
orderby x
select x;
}
@@ -58,15 +58,15 @@ namespace Duplicati.UnitTest
{
base.OneTimeSetUp();
- if (!File.Exists(zipAlternativeFilepath))
+ if (!systemIO.FileExists(zipAlternativeFilepath))
{
var url = $"{S3_URL}{this.zipFilename}";
DownloadS3FileIfNewer(zipFilepath, url);
- System.IO.Compression.ZipFile.ExtractToDirectory(this.zipFilepath, BASEFOLDER);
+ ZipFileExtractToDirectory(this.zipFilepath, BASEFOLDER);
}
else
{
- System.IO.Compression.ZipFile.ExtractToDirectory(this.zipAlternativeFilepath, BASEFOLDER);
+ ZipFileExtractToDirectory(this.zipAlternativeFilepath, BASEFOLDER);
}
}
@@ -74,9 +74,9 @@ namespace Duplicati.UnitTest
{
var webRequest = (HttpWebRequest)WebRequest.Create(url);
- if (File.Exists(destinationFilePath))
+ if (systemIO.FileExists(destinationFilePath))
{
- webRequest.IfModifiedSince = File.GetLastWriteTimeUtc(destinationFilePath);
+ webRequest.IfModifiedSince = systemIO.FileGetLastWriteTimeUtc(destinationFilePath);
}
try
@@ -104,9 +104,9 @@ namespace Duplicati.UnitTest
public override void OneTimeTearDown()
{
- if (Directory.Exists(this.SOURCEFOLDER))
+ if (systemIO.DirectoryExists(this.SOURCEFOLDER))
{
- Directory.Delete(this.SOURCEFOLDER, true);
+ systemIO.DirectoryDelete(this.SOURCEFOLDER, true);
}
}
@@ -143,9 +143,9 @@ namespace Duplicati.UnitTest
var targetfolder = Path.Combine(DATAFOLDER, foldername);
ProgressWriteLine("Adding folder {0} to source", foldername);
- Directory.Move(n, targetfolder);
+ systemIO.DirectoryMove(n, targetfolder);
- var size = Directory.EnumerateFiles(targetfolder, "*", SearchOption.AllDirectories).Select(x => new FileInfo(x).Length).Sum();
+ var size = systemIO.EnumerateFiles(targetfolder, "*", SearchOption.AllDirectories).Select(systemIO.FileLength).Sum();
ProgressWriteLine("Running backup with {0} data added ...", Duplicati.Library.Utility.Utility.FormatSizeString(size));
using (new Library.Logging.Timer(LOGTAG, "BackupWithDataAdded", string.Format("Backup with {0} data added", Duplicati.Library.Utility.Utility.FormatSizeString(size))))
@@ -161,29 +161,29 @@ namespace Duplicati.UnitTest
using (new Library.Logging.Timer(LOGTAG, "UnchangedBackup", "Unchanged backup"))
Duplicati.CommandLine.Program.RealMain(backupargs);
- var datafolders = Directory.EnumerateDirectories(DATAFOLDER);
+ var datafolders = systemIO.EnumerateDirectories(DATAFOLDER);
var f = datafolders.Skip(datafolders.Count() / 2).First();
ProgressWriteLine("Renaming folder {0}", Path.GetFileName(f));
- Directory.Move(f, Path.Combine(Path.GetDirectoryName(f), Path.GetFileName(f) + "-renamed"));
+ systemIO.DirectoryMove(f, Path.Combine(Path.GetDirectoryName(f), Path.GetFileName(f) + "-renamed"));
ProgressWriteLine("Running backup with renamed folder...");
using (new Library.Logging.Timer(LOGTAG, "BackupWithRenamedFolder", "Backup with renamed folder"))
Duplicati.CommandLine.Program.RealMain(backupargs);
- datafolders = Directory.EnumerateDirectories(DATAFOLDER);
+ datafolders = systemIO.EnumerateDirectories(DATAFOLDER);
ProgressWriteLine("Deleting data");
var rm1 = datafolders.First();
var rm2 = datafolders.Skip(1).First();
var rm3 = datafolders.Skip(2).First();
- Directory.Delete(rm1, true);
- Directory.Delete(rm2, true);
- var rmfiles = Directory.EnumerateFiles(rm3, "*", SearchOption.AllDirectories);
+ systemIO.DirectoryDelete(rm1, true);
+ systemIO.DirectoryDelete(rm2, true);
+ var rmfiles = systemIO.EnumerateFiles(rm3, "*", SearchOption.AllDirectories);
foreach (var n in rmfiles.Take(rmfiles.Count() / 2))
- File.Delete(n);
+ systemIO.FileDelete(n);
ProgressWriteLine("Running backup with deleted data...");
using (new Library.Logging.Timer(LOGTAG, "BackupWithDeletedData", "Backup with deleted data"))
@@ -196,7 +196,7 @@ namespace Duplicati.UnitTest
for (var i = 0; i < 5; i++)
{
ProgressWriteLine("Running backup with changed logfile {0} of {1} ...", i + 1, 5);
- File.Copy(LOGFILE, Path.Combine(SOURCEFOLDER, Path.GetFileName(LOGFILE)), true);
+ systemIO.FileCopy(LOGFILE, Path.Combine(SOURCEFOLDER, Path.GetFileName(LOGFILE)), true);
using (new Library.Logging.Timer(LOGTAG, "BackupWithLogfileChange", string.Format("Backup with logfilechange {0}", i + 1)))
Duplicati.CommandLine.Program.RealMain(backupargs);
@@ -207,7 +207,7 @@ namespace Duplicati.UnitTest
Duplicati.CommandLine.Program.RealMain((new string[] { "compact", target, "--small-file-max-count=2" }.Union(opts)).ToArray());
- datafolders = Directory.EnumerateDirectories(DATAFOLDER);
+ datafolders = systemIO.EnumerateDirectories(DATAFOLDER);
var rf = datafolders.Skip(datafolders.Count() - 2).First();
ProgressWriteLine("Partial restore of {0} ...", Path.GetFileName(rf));
@@ -218,7 +218,7 @@ namespace Duplicati.UnitTest
using (new Library.Logging.Timer(LOGTAG, "VerifiationOfPartialRestore", "Verification of partial restored files"))
TestUtils.VerifyDir(rf, RESTOREFOLDER, true);
- Directory.Delete(RESTOREFOLDER, true);
+ systemIO.DirectoryDelete(RESTOREFOLDER, true);
ProgressWriteLine("Partial restore of {0} without local db...", Path.GetFileName(rf));
using (new Library.Logging.Timer(LOGTAG, "PartialRestoreWithoutLocalDb", "Partial restore without local db"))
@@ -228,7 +228,7 @@ namespace Duplicati.UnitTest
using (new Library.Logging.Timer(LOGTAG, "VerificationOfPartialRestore", "Verification of partial restored files"))
TestUtils.VerifyDir(rf, RESTOREFOLDER, true);
- Directory.Delete(RESTOREFOLDER, true);
+ systemIO.DirectoryDelete(RESTOREFOLDER, true);
ProgressWriteLine("Full restore ...");
using (new Library.Logging.Timer(LOGTAG, "FullRestore", "Full restore"))
@@ -236,10 +236,10 @@ namespace Duplicati.UnitTest
ProgressWriteLine("Verifying full restore ...");
using (new Library.Logging.Timer(LOGTAG, "VerificationOfFullRestore", "Verification of restored files"))
- foreach (var s in Directory.EnumerateDirectories(DATAFOLDER))
+ foreach (var s in systemIO.EnumerateDirectories(DATAFOLDER))
TestUtils.VerifyDir(s, Path.Combine(RESTOREFOLDER, Path.GetFileName(s)), true);
- Directory.Delete(RESTOREFOLDER, true);
+ systemIO.DirectoryDelete(RESTOREFOLDER, true);
ProgressWriteLine("Full restore without local db...");
using (new Library.Logging.Timer(LOGTAG, "FullRestoreWithoutDb", "Full restore without local db"))
@@ -247,7 +247,7 @@ namespace Duplicati.UnitTest
ProgressWriteLine("Verifying full restore ...");
using (new Library.Logging.Timer(LOGTAG, "VerificationOfFullRestoreWithoutDb", "Verification of restored files"))
- foreach (var s in Directory.EnumerateDirectories(DATAFOLDER))
+ foreach (var s in systemIO.EnumerateDirectories(DATAFOLDER))
TestUtils.VerifyDir(s, Path.Combine(RESTOREFOLDER, Path.GetFileName(s)), true);
ProgressWriteLine("Testing data ...");
diff --git a/Duplicati/UnitTest/Duplicati.UnitTest.csproj b/Duplicati/UnitTest/Duplicati.UnitTest.csproj
index b06fa183d..699294732 100644
--- a/Duplicati/UnitTest/Duplicati.UnitTest.csproj
+++ b/Duplicati/UnitTest/Duplicati.UnitTest.csproj
@@ -40,6 +40,7 @@
<HintPath>..\..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
</ItemGroup>
<ItemGroup>
diff --git a/Duplicati/UnitTest/ProblematicPathTests.cs b/Duplicati/UnitTest/ProblematicPathTests.cs
index 42bc7c46b..7d1f05a3a 100644
--- a/Duplicati/UnitTest/ProblematicPathTests.cs
+++ b/Duplicati/UnitTest/ProblematicPathTests.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -14,33 +13,6 @@ namespace Duplicati.UnitTest
[TestFixture]
public class ProblematicPathTests : BasicSetupHelper
{
- /// <summary>
- /// This is a helper class that removes problematic paths that the built-in classes
- /// have trouble with (e.g., paths that end with a dot or space on Windows).
- /// </summary>
- private class DisposablePath : IDisposable
- {
- private readonly string path;
-
- public DisposablePath(string path)
- {
- this.path = path;
- }
-
- public void Dispose()
- {
- if (SystemIO.IO_OS.FileExists(this.path))
- {
- SystemIO.IO_OS.FileDelete(this.path);
- }
-
- if (SystemIO.IO_OS.DirectoryExists(this.path))
- {
- SystemIO.IO_OS.DirectoryDelete(this.path);
- }
- }
- }
-
private static void WriteFile(string path, byte[] contents)
{
using (FileStream fileStream = SystemIO.IO_OS.FileOpenWrite(path))
@@ -59,61 +31,48 @@ namespace Duplicati.UnitTest
// A long path to exclude.
string longFile = SystemIO.IO_OS.PathCombine(this.DATAFOLDER, new string('y', 255));
- using (new DisposablePath(longFile))
+ WriteFile(longFile, new byte[] {0, 1});
+
+ // A folder that ends with a dot to exclude.
+ string folderWithDot = Path.Combine(this.DATAFOLDER, "folder_with_dot.");
+ SystemIO.IO_OS.DirectoryCreate(folderWithDot);
+
+ // A folder that ends with a space to exclude.
+ string folderWithSpace = Path.Combine(this.DATAFOLDER, "folder_with_space ");
+ SystemIO.IO_OS.DirectoryCreate(folderWithSpace);
+
+ // A file that ends with a dot to exclude.
+ string fileWithDot = Path.Combine(this.DATAFOLDER, "file_with_dot.");
+ WriteFile(fileWithDot, new byte[] {0, 1});
+
+ // A file that ends with a space to exclude.
+ string fileWithSpace = Path.Combine(this.DATAFOLDER, "file_with_space ");
+ WriteFile(fileWithSpace, new byte[] {0, 1});
+
+ FilterExpression filter = new FilterExpression(longFile, false);
+ filter = FilterExpression.Combine(filter, new FilterExpression(Util.AppendDirSeparator(folderWithDot), false));
+ filter = FilterExpression.Combine(filter, new FilterExpression(Util.AppendDirSeparator(folderWithSpace), false));
+ filter = FilterExpression.Combine(filter, new FilterExpression(fileWithDot, false));
+ filter = FilterExpression.Combine(filter, new FilterExpression(fileWithSpace, false));
+
+ Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
{
- WriteFile(longFile, new byte[] {0, 1});
-
- // A folder that ends with a dot to exclude.
- string folderWithDot = Path.Combine(this.DATAFOLDER, "folder_with_dot.");
- SystemIO.IO_OS.DirectoryCreate(folderWithDot);
- using (new DisposablePath(folderWithDot))
- {
- // A folder that ends with a space to exclude.
- string folderWithSpace = Path.Combine(this.DATAFOLDER, "folder_with_space ");
- SystemIO.IO_OS.DirectoryCreate(folderWithSpace);
- using (new DisposablePath(folderWithSpace))
- {
- // A file that ends with a dot to exclude.
- string fileWithDot = Path.Combine(this.DATAFOLDER, "file_with_dot.");
- using (new DisposablePath(fileWithDot))
- {
- WriteFile(fileWithDot, new byte[] {0, 1});
-
- // A file that ends with a space to exclude.
- string fileWithSpace = Path.Combine(this.DATAFOLDER, "file_with_space ");
- using (new DisposablePath(fileWithSpace))
- {
- WriteFile(fileWithSpace, new byte[] {0, 1});
-
- FilterExpression filter = new FilterExpression(longFile, false);
- filter = FilterExpression.Combine(filter, new FilterExpression(Util.AppendDirSeparator(folderWithDot), false));
- filter = FilterExpression.Combine(filter, new FilterExpression(Util.AppendDirSeparator(folderWithSpace), false));
- filter = FilterExpression.Combine(filter, new FilterExpression(fileWithDot, false));
- filter = FilterExpression.Combine(filter, new FilterExpression(fileWithSpace, false));
-
- Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
- {
- IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER}, filter);
- Assert.AreEqual(0, backupResults.Errors.Count());
- Assert.AreEqual(0, backupResults.Warnings.Count());
- }
-
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
- {
- IListResults listResults = c.List("*");
- Assert.AreEqual(0, listResults.Errors.Count());
- Assert.AreEqual(0, listResults.Warnings.Count());
-
- string[] backedUpPaths = listResults.Files.Select(x => x.Path).ToArray();
- Assert.AreEqual(2, backedUpPaths.Length);
- Assert.Contains(Util.AppendDirSeparator(this.DATAFOLDER), backedUpPaths);
- Assert.Contains(normalFilePath, backedUpPaths);
- }
- }
- }
- }
- }
+ IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER}, filter);
+ Assert.AreEqual(0, backupResults.Errors.Count());
+ Assert.AreEqual(0, backupResults.Warnings.Count());
+ }
+
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
+ {
+ IListResults listResults = c.List("*");
+ Assert.AreEqual(0, listResults.Errors.Count());
+ Assert.AreEqual(0, listResults.Warnings.Count());
+
+ string[] backedUpPaths = listResults.Files.Select(x => x.Path).ToArray();
+ Assert.AreEqual(2, backedUpPaths.Length);
+ Assert.Contains(Util.AppendDirSeparator(this.DATAFOLDER), backedUpPaths);
+ Assert.Contains(normalFilePath, backedUpPaths);
}
}
@@ -123,46 +82,38 @@ namespace Duplicati.UnitTest
{
string folderPath = Path.Combine(this.DATAFOLDER, new string('x', 10));
SystemIO.IO_OS.DirectoryCreate(folderPath);
- using (new DisposablePath(folderPath))
+
+ string fileName = new string('y', 255);
+ string filePath = SystemIO.IO_OS.PathCombine(folderPath, fileName);
+ byte[] fileBytes = {0, 1, 2};
+ WriteFile(filePath, fileBytes);
+
+ Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
+ {
+ IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER});
+ Assert.AreEqual(0, backupResults.Errors.Count());
+ Assert.AreEqual(0, backupResults.Warnings.Count());
+ }
+
+ Dictionary<string, string> restoreOptions = new Dictionary<string, string>(this.TestOptions) {["restore-path"] = this.RESTOREFOLDER};
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, restoreOptions, null))
+ {
+ IRestoreResults restoreResults = c.Restore(new[] {filePath});
+ Assert.AreEqual(0, restoreResults.Errors.Count());
+ Assert.AreEqual(0, restoreResults.Warnings.Count());
+ }
+
+ string restoreFilePath = SystemIO.IO_OS.PathCombine(this.RESTOREFOLDER, fileName);
+ Assert.IsTrue(SystemIO.IO_OS.FileExists(restoreFilePath));
+
+ MemoryStream restoredStream = new MemoryStream();
+ using (FileStream fileStream = SystemIO.IO_OS.FileOpenRead(restoreFilePath))
{
- string fileName = new string('y', 255);
- string filePath = SystemIO.IO_OS.PathCombine(folderPath, fileName);
- using (new DisposablePath(filePath))
- {
- byte[] fileBytes = {0, 1, 2};
- WriteFile(filePath, fileBytes);
-
- Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
- {
- IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER});
- Assert.AreEqual(0, backupResults.Errors.Count());
- Assert.AreEqual(0, backupResults.Warnings.Count());
- }
-
- string restoreFilePath = SystemIO.IO_OS.PathCombine(this.RESTOREFOLDER, fileName);
- using (new DisposablePath(restoreFilePath))
- {
- Dictionary<string, string> restoreOptions = new Dictionary<string, string>(this.TestOptions) {["restore-path"] = this.RESTOREFOLDER};
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, restoreOptions, null))
- {
- IRestoreResults restoreResults = c.Restore(new[] {filePath});
- Assert.AreEqual(0, restoreResults.Errors.Count());
- Assert.AreEqual(0, restoreResults.Warnings.Count());
- }
-
- Assert.IsTrue(SystemIO.IO_OS.FileExists(restoreFilePath));
-
- MemoryStream restoredStream = new MemoryStream();
- using (FileStream fileStream = SystemIO.IO_OS.FileOpenRead(restoreFilePath))
- {
- Utility.CopyStream(fileStream, restoredStream);
- }
-
- Assert.AreEqual(fileBytes, restoredStream.ToArray());
- }
- }
+ Utility.CopyStream(fileStream, restoredStream);
}
+
+ Assert.AreEqual(fileBytes, restoredStream.ToArray());
}
[Test]
@@ -175,45 +126,37 @@ namespace Duplicati.UnitTest
{
string folderPath = SystemIO.IO_OS.PathCombine(this.DATAFOLDER, pathComponent);
SystemIO.IO_OS.DirectoryCreate(folderPath);
- using (new DisposablePath(folderPath))
+
+ string filePath = SystemIO.IO_OS.PathCombine(folderPath, pathComponent);
+ byte[] fileBytes = {0, 1, 2};
+ WriteFile(filePath, fileBytes);
+
+ Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
{
- string filePath = SystemIO.IO_OS.PathCombine(folderPath, pathComponent);
- using (new DisposablePath(filePath))
- {
- byte[] fileBytes = {0, 1, 2};
- WriteFile(filePath, fileBytes);
-
- Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null))
- {
- IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER});
- Assert.AreEqual(0, backupResults.Errors.Count());
- Assert.AreEqual(0, backupResults.Warnings.Count());
- }
-
- string restoreFilePath = SystemIO.IO_OS.PathCombine(this.RESTOREFOLDER, pathComponent);
- using (new DisposablePath(restoreFilePath))
- {
- Dictionary<string, string> restoreOptions = new Dictionary<string, string>(this.TestOptions) {["restore-path"] = this.RESTOREFOLDER};
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, restoreOptions, null))
- {
- IRestoreResults restoreResults = c.Restore(new[] {filePath});
- Assert.AreEqual(0, restoreResults.Errors.Count());
- Assert.AreEqual(0, restoreResults.Warnings.Count());
- }
-
- Assert.IsTrue(SystemIO.IO_OS.FileExists(restoreFilePath));
-
- MemoryStream restoredStream = new MemoryStream();
- using (FileStream fileStream = SystemIO.IO_OS.FileOpenRead(restoreFilePath))
- {
- Utility.CopyStream(fileStream, restoredStream);
- }
-
- Assert.AreEqual(fileBytes, restoredStream.ToArray());
- }
- }
+ IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER});
+ Assert.AreEqual(0, backupResults.Errors.Count());
+ Assert.AreEqual(0, backupResults.Warnings.Count());
}
+
+ Dictionary<string, string> restoreOptions = new Dictionary<string, string>(this.TestOptions) {["restore-path"] = this.RESTOREFOLDER};
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, restoreOptions, null))
+ {
+ IRestoreResults restoreResults = c.Restore(new[] {filePath});
+ Assert.AreEqual(0, restoreResults.Errors.Count());
+ Assert.AreEqual(0, restoreResults.Warnings.Count());
+ }
+
+ string restoreFilePath = SystemIO.IO_OS.PathCombine(this.RESTOREFOLDER, pathComponent);
+ Assert.IsTrue(SystemIO.IO_OS.FileExists(restoreFilePath));
+
+ MemoryStream restoredStream = new MemoryStream();
+ using (FileStream fileStream = SystemIO.IO_OS.FileOpenRead(restoreFilePath))
+ {
+ Utility.CopyStream(fileStream, restoredStream);
+ }
+
+ Assert.AreEqual(fileBytes, restoredStream.ToArray());
}
}
} \ No newline at end of file