Respect DryRun option when scanning target blocks

This commit is contained in:
FootStark
2016-03-12 12:48:41 +01:00
parent 213cf5c1fd
commit 27ce3ef5f3
2 changed files with 14 additions and 6 deletions
@@ -1067,8 +1067,8 @@ namespace Duplicati.Library.Main.Database
m_hasUpdates = true;
m_updateFileAsDataVerifiedCommand.SetParameterValue(0, targetfileid);
var r = m_updateFileAsDataVerifiedCommand.ExecuteNonQuery();
if (r <= 0)
throw new Exception("Unexpected reset result");
if (r != 1)
throw new Exception("Unexpected result when marking file as verified.");
}
public void SetBlockRestored(long targetfileid, long index, string hash, long size, bool metadata)
@@ -921,15 +921,23 @@ namespace Duplicati.Library.Main.Operation
var currentAttr = m_systemIO.GetFileAttributes(targetpath);
if ((currentAttr & System.IO.FileAttributes.ReadOnly) != 0)
{ // clear readonly attribute
if ((currentfilelength > restorelist.Length) || !fullfilehashmatch)
m_systemIO.SetFileAttributes(targetpath, currentAttr & ~System.IO.FileAttributes.ReadOnly);
if ((currentfilelength > targetfilelength) || !fullfilehashmatch)
{
if (options.Dryrun)
result.AddDryrunMessage(string.Format("Would reset read-only attribute on file: {0}", targetpath));
else
m_systemIO.SetFileAttributes(targetpath, currentAttr & ~System.IO.FileAttributes.ReadOnly);
}
}
// Adjust file length if necessary (smaller is ok, will be extended during restore)
if (currentfilelength > targetfilelength)
{
using (var file = m_systemIO.FileOpenWrite(targetpath))
file.SetLength(targetfilelength);
if (options.Dryrun)
result.AddDryrunMessage(string.Format("Would truncate file '{0}' to length of {1:N0} bytes", targetpath, targetfilelength));
else
using (var file = m_systemIO.FileOpenWrite(targetpath))
file.SetLength(targetfilelength);
}
}