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:
Diffstat (limited to 'Duplicati/Library/Main/Operation/RestoreHandler.cs')
-rw-r--r--Duplicati/Library/Main/Operation/RestoreHandler.cs98
1 files changed, 48 insertions, 50 deletions
diff --git a/Duplicati/Library/Main/Operation/RestoreHandler.cs b/Duplicati/Library/Main/Operation/RestoreHandler.cs
index 5ab45830e..b661a061b 100644
--- a/Duplicati/Library/Main/Operation/RestoreHandler.cs
+++ b/Duplicati/Library/Main/Operation/RestoreHandler.cs
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using Duplicati.Library.Interface;
-using Duplicati.Library.IO;
+using Duplicati.Library.Common.IO;
using Duplicati.Library.Main.Database;
using Duplicati.Library.Main.Volumes;
@@ -20,7 +19,6 @@ namespace Duplicati.Library.Main.Operation
private readonly Options m_options;
private byte[] m_blockbuffer;
private readonly RestoreResults m_result;
- private static readonly ISystemIO m_systemIO = SystemIO.IO_OS(Duplicati.Library.Utility.Utility.IsClientWindows);
private static readonly string DIRSEP = Util.DirectorySeparatorString;
public RestoreHandler(string backendurl, Options options, RestoreResults result)
@@ -88,7 +86,7 @@ namespace Duplicati.Library.Main.Operation
// If we have both target paths and a filter, combine into a single filter
filter = Library.Utility.JoinedFilterExpression.Join(new Library.Utility.FilterExpression(paths), filter);
- if (!m_options.NoLocalDb && m_systemIO.FileExists(m_options.Dbpath))
+ if (!m_options.NoLocalDb && SystemIO.IO_OS.FileExists(m_options.Dbpath))
{
using(var db = new LocalRestoreDatabase(m_options.Dbpath))
{
@@ -162,16 +160,16 @@ namespace Duplicati.Library.Main.Operation
try
{
- var folderpath = m_systemIO.PathGetDirectoryName(targetpath);
- if (!options.Dryrun && !m_systemIO.DirectoryExists(folderpath))
+ var folderpath = SystemIO.IO_OS.PathGetDirectoryName(targetpath);
+ if (!options.Dryrun && !SystemIO.IO_OS.DirectoryExists(folderpath))
{
Logging.Log.WriteWarningMessage(LOGTAG, "CreateMissingFolder", null, "Creating missing folder {0} for file {1}", folderpath, targetpath);
- m_systemIO.DirectoryCreate(folderpath);
+ SystemIO.IO_OS.DirectoryCreate(folderpath);
}
// TODO: Much faster if we iterate the volume and checks what blocks are used,
// because the compressors usually like sequential reading
- using(var file = m_systemIO.FileOpenWrite(targetpath))
+ using(var file = SystemIO.IO_OS.FileOpenWrite(targetpath))
foreach(var targetblock in restorelist.Blocks)
{
file.Position = targetblock.Offset;
@@ -270,10 +268,10 @@ namespace Duplicati.Library.Main.Operation
try
{
var folderpath = Duplicati.Library.Utility.Utility.GetParent(targetpath, false);
- if (!options.Dryrun && !m_systemIO.DirectoryExists(folderpath))
+ if (!options.Dryrun && !SystemIO.IO_OS.DirectoryExists(folderpath))
{
Logging.Log.WriteWarningMessage(LOGTAG, "CreateMissingFolder", null, "Creating missing folder {0} for target {1}", folderpath, targetpath);
- m_systemIO.DirectoryCreate(folderpath);
+ SystemIO.IO_OS.DirectoryCreate(folderpath);
}
ApplyMetadata(targetpath, metainfo.Value, options.RestorePermissions, options.RestoreSymlinkMetadata, options.Dryrun);
@@ -398,7 +396,7 @@ namespace Duplicati.Library.Main.Operation
// Restore empty files. They might not have any blocks so don't appear in any volume.
foreach (var file in database.GetFilesToRestore(true).Where(item => item.Length == 0)) {
// Just create the file and close it right away, empty statement is intentional.
- using (m_systemIO.FileCreate(file.Path))
+ using (SystemIO.IO_OS.FileCreate(file.Path))
{
}
}
@@ -438,7 +436,7 @@ namespace Duplicati.Library.Main.Operation
string key;
long size;
- using(var fs = m_systemIO.FileOpenRead(file.Path))
+ using(var fs = SystemIO.IO_OS.FileOpenRead(file.Path))
{
size = fs.Length;
key = Convert.ToBase64String(filehasher.ComputeHash(fs));
@@ -492,13 +490,13 @@ namespace Duplicati.Library.Main.Operation
// Make the symlink first, otherwise we cannot apply metadata to it
if (metadata.TryGetValue("CoreSymlinkTarget", out k))
- m_systemIO.CreateSymlink(targetpath, k, isDirTarget);
+ SystemIO.IO_OS.CreateSymlink(targetpath, k, isDirTarget);
// If the target is a folder, make sure we create it first
- else if (isDirTarget && !m_systemIO.DirectoryExists(targetpath))
- m_systemIO.DirectoryCreate(targetpath);
+ else if (isDirTarget && !SystemIO.IO_OS.DirectoryExists(targetpath))
+ SystemIO.IO_OS.DirectoryCreate(targetpath);
// Avoid setting restoring symlink metadata, as that writes the symlink target, not the symlink itself
- if (!restoreSymlinkMetadata && Snapshots.SnapshotUtility.IsSymlink(m_systemIO, targetpath))
+ if (!restoreSymlinkMetadata && Snapshots.SnapshotUtility.IsSymlink(SystemIO.IO_OS, targetpath))
{
Logging.Log.WriteVerboseMessage(LOGTAG, "no-symlink-metadata-restored", "Not applying metadata to symlink: {0}", targetpath);
return;
@@ -507,23 +505,23 @@ namespace Duplicati.Library.Main.Operation
if (metadata.TryGetValue("CoreLastWritetime", out k) && long.TryParse(k, out t))
{
if (isDirTarget)
- m_systemIO.DirectorySetLastWriteTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
+ SystemIO.IO_OS.DirectorySetLastWriteTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
else
- m_systemIO.FileSetLastWriteTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
+ SystemIO.IO_OS.FileSetLastWriteTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
}
if (metadata.TryGetValue("CoreCreatetime", out k) && long.TryParse(k, out t))
{
if (isDirTarget)
- m_systemIO.DirectorySetCreationTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
+ SystemIO.IO_OS.DirectorySetCreationTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
else
- m_systemIO.FileSetCreationTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
+ SystemIO.IO_OS.FileSetCreationTimeUtc(targetpath, new DateTime(t, DateTimeKind.Utc));
}
if (metadata.TryGetValue("CoreAttributes", out k) && Enum.TryParse(k, true, out fa))
- m_systemIO.SetFileAttributes(targetpath, fa);
+ SystemIO.IO_OS.SetFileAttributes(targetpath, fa);
- m_systemIO.SetMetadata(path, metadata, restorePermissions);
+ SystemIO.IO_OS.SetMetadata(path, metadata, restorePermissions);
}
}
@@ -542,20 +540,20 @@ namespace Duplicati.Library.Main.Operation
try
{
- if (m_systemIO.FileExists(sourcepath))
+ if (SystemIO.IO_OS.FileExists(sourcepath))
{
- var folderpath = m_systemIO.PathGetDirectoryName(targetpath);
- if (!options.Dryrun && !m_systemIO.DirectoryExists(folderpath))
+ var folderpath = SystemIO.IO_OS.PathGetDirectoryName(targetpath);
+ if (!options.Dryrun && !SystemIO.IO_OS.DirectoryExists(folderpath))
{
Logging.Log.WriteWarningMessage(LOGTAG, "CreateMissingFolder", null, "Creating missing folder {0} for file {1}", folderpath, targetpath);
- m_systemIO.DirectoryCreate(folderpath);
+ SystemIO.IO_OS.DirectoryCreate(folderpath);
}
- using(var targetstream = options.Dryrun ? null : m_systemIO.FileOpenWrite(targetpath))
+ using(var targetstream = options.Dryrun ? null : SystemIO.IO_OS.FileOpenWrite(targetpath))
{
try
{
- using(var sourcestream = m_systemIO.FileOpenRead(sourcepath))
+ using(var sourcestream = SystemIO.IO_OS.FileOpenRead(sourcepath))
{
foreach(var block in entry.Blocks)
{
@@ -648,14 +646,14 @@ namespace Duplicati.Library.Main.Operation
if (result.TaskControlRendevouz() == TaskControlState.Stop)
return;
- var folderpath = m_systemIO.PathGetDirectoryName(targetpath);
- if (!options.Dryrun && !m_systemIO.DirectoryExists(folderpath))
+ var folderpath = SystemIO.IO_OS.PathGetDirectoryName(targetpath);
+ if (!options.Dryrun && !SystemIO.IO_OS.DirectoryExists(folderpath))
{
Logging.Log.WriteWarningMessage(LOGTAG, "CreateMissingFolder", null, "Creating missing folder {0} for file {1}", folderpath, targetpath);
- m_systemIO.DirectoryCreate(folderpath);
+ SystemIO.IO_OS.DirectoryCreate(folderpath);
}
- using (var file = options.Dryrun ? null : m_systemIO.FileOpenWrite(targetpath))
+ using (var file = options.Dryrun ? null : SystemIO.IO_OS.FileOpenWrite(targetpath))
foreach (var targetblock in restorelist.Blocks)
{
foreach (var source in targetblock.Blocksources)
@@ -665,7 +663,7 @@ namespace Duplicati.Library.Main.Operation
if (result.TaskControlRendevouz() == TaskControlState.Stop)
return;
- if (m_systemIO.FileExists(source.Path))
+ if (SystemIO.IO_OS.FileExists(source.Path))
{
if (source.IsMetadata)
{
@@ -676,7 +674,7 @@ namespace Duplicati.Library.Main.Operation
}
else
{
- using (var sourcefile = m_systemIO.FileOpenRead(source.Path))
+ using (var sourcefile = SystemIO.IO_OS.FileOpenRead(source.Path))
{
sourcefile.Position = source.Offset;
int size = Library.Utility.Utility.ForceStreamRead(sourcefile, blockbuffer, blockbuffer.Length);
@@ -778,14 +776,14 @@ namespace Duplicati.Library.Main.Operation
{
// This part is not protected by try/catch as we need the target folder to exist
if (!string.IsNullOrEmpty(options.Restorepath))
- if (!m_systemIO.DirectoryExists(options.Restorepath))
+ if (!SystemIO.IO_OS.DirectoryExists(options.Restorepath))
{
Logging.Log.WriteVerboseMessage(LOGTAG, "CreateFolder", "Creating folder: {0}", options.Restorepath);
if (options.Dryrun)
Logging.Log.WriteDryrunMessage(LOGTAG, "WouldCreateFolder", "Would create folder: {0}", options.Restorepath);
else
- m_systemIO.DirectoryCreate(options.Restorepath);
+ SystemIO.IO_OS.DirectoryCreate(options.Restorepath);
}
foreach (var folder in database.GetTargetFolders())
@@ -795,7 +793,7 @@ namespace Duplicati.Library.Main.Operation
if (result.TaskControlRendevouz() == TaskControlState.Stop)
return;
- if (!m_systemIO.DirectoryExists(folder))
+ if (!SystemIO.IO_OS.DirectoryExists(folder))
{
result.FoldersRestored++;
@@ -804,7 +802,7 @@ namespace Duplicati.Library.Main.Operation
if (options.Dryrun)
Logging.Log.WriteDryrunMessage(LOGTAG, "WouldCreateFolder", "Would create folder: {0}", folder);
else
- m_systemIO.DirectoryCreate(folder);
+ SystemIO.IO_OS.DirectoryCreate(folder);
}
}
catch (Exception ex)
@@ -829,14 +827,14 @@ namespace Duplicati.Library.Main.Operation
var targetfileid = restorelist.TargetFileID;
var targetfilehash = restorelist.TargetHash;
var targetfilelength = restorelist.Length;
- if (m_systemIO.FileExists(targetpath))
+ if (SystemIO.IO_OS.FileExists(targetpath))
{
try
{
if (result.TaskControlRendevouz() == TaskControlState.Stop)
return;
- var currentfilelength = m_systemIO.FileLength(targetpath);
+ var currentfilelength = SystemIO.IO_OS.FileLength(targetpath);
var wasTruncated = false;
// Adjust file length in overwrite mode if necessary (smaller is ok, will be extended during restore)
@@ -844,18 +842,18 @@ namespace Duplicati.Library.Main.Operation
// be truncated (i.e. forthwritten log files).
if (!rename && currentfilelength > targetfilelength)
{
- var currentAttr = m_systemIO.GetFileAttributes(targetpath);
+ var currentAttr = SystemIO.IO_OS.GetFileAttributes(targetpath);
if ((currentAttr & System.IO.FileAttributes.ReadOnly) != 0) // clear readonly attribute
{
if (options.Dryrun)
Logging.Log.WriteDryrunMessage(LOGTAG, "WouldResetReadOnlyAttribute", "Would reset read-only attribute on file: {0}", targetpath);
- else m_systemIO.SetFileAttributes(targetpath, currentAttr & ~System.IO.FileAttributes.ReadOnly);
+ else SystemIO.IO_OS.SetFileAttributes(targetpath, currentAttr & ~System.IO.FileAttributes.ReadOnly);
}
if (options.Dryrun)
Logging.Log.WriteDryrunMessage(LOGTAG, "WouldTruncateFile", "Would truncate file '{0}' to length of {1:N0} bytes", targetpath, targetfilelength);
else
{
- using (var file = m_systemIO.FileOpenWrite(targetpath))
+ using (var file = SystemIO.IO_OS.FileOpenWrite(targetpath))
file.SetLength(targetfilelength);
currentfilelength = targetfilelength;
}
@@ -873,7 +871,7 @@ namespace Duplicati.Library.Main.Operation
bool calcFileHash = (currentfilelength == targetfilelength);
if (calcFileHash) filehasher.Initialize();
- using (var file = m_systemIO.FileOpenRead(targetpath))
+ using (var file = SystemIO.IO_OS.FileOpenRead(targetpath))
using (var block = new Blockprocessor(file, blockbuffer))
foreach (var targetblock in restorelist.Blocks)
{
@@ -923,12 +921,12 @@ namespace Duplicati.Library.Main.Operation
if (!rename && !fullfilehashmatch && !wasTruncated) // Reset read-only attribute (if set) to overwrite
{
- var currentAttr = m_systemIO.GetFileAttributes(targetpath);
+ var currentAttr = SystemIO.IO_OS.GetFileAttributes(targetpath);
if ((currentAttr & System.IO.FileAttributes.ReadOnly) != 0)
{
if (options.Dryrun)
Logging.Log.WriteDryrunMessage(LOGTAG, "WouldResetReadOnlyAttribyte", "Would reset read-only attribute on file: {0}", targetpath);
- else m_systemIO.SetFileAttributes(targetpath, currentAttr & ~System.IO.FileAttributes.ReadOnly);
+ else SystemIO.IO_OS.SetFileAttributes(targetpath, currentAttr & ~System.IO.FileAttributes.ReadOnly);
}
}
@@ -972,15 +970,15 @@ namespace Duplicati.Library.Main.Operation
if (rename)
{
//Select a new filename
- var ext = m_systemIO.PathGetExtension(targetpath) ?? "";
+ var ext = SystemIO.IO_OS.PathGetExtension(targetpath) ?? "";
if (!string.IsNullOrEmpty(ext) && !ext.StartsWith(".", StringComparison.Ordinal))
ext = "." + ext;
// First we try with a simple date append, assuming that there are not many conflicts there
- var newname = m_systemIO.PathChangeExtension(targetpath, null) + "." + database.RestoreTime.ToLocalTime().ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
+ var newname = SystemIO.IO_OS.PathChangeExtension(targetpath, null) + "." + database.RestoreTime.ToLocalTime().ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
var tr = newname + ext;
var c = 0;
- while (m_systemIO.FileExists(tr) && c < 1000)
+ while (SystemIO.IO_OS.FileExists(tr) && c < 1000)
{
try
{
@@ -989,7 +987,7 @@ namespace Duplicati.Library.Main.Operation
filehasher.Initialize();
string key;
- using(var file = m_systemIO.FileOpenRead(tr))
+ using(var file = SystemIO.IO_OS.FileOpenRead(tr))
key = Convert.ToBase64String(filehasher.ComputeHash(file));
if (key == targetfilehash)