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-01-19 01:04:48 +0300
committerKenneth Hsu <kennethhsu@gmail.com>2020-01-19 01:44:05 +0300
commit25d7cea6c7687d9174fe85cc13037b33999d9244 (patch)
treea0421beb2e34b6f3b7820d7f9df3611ed52dd320 /Duplicati/CommandLine
parentbfbae6fcaf9ca5f65327dc975e586aede0d18745 (diff)
Dispose of HashLookupHelper after use.
The HashLookupHelper contains an open FileStream that needs to be closed.
Diffstat (limited to 'Duplicati/CommandLine')
-rw-r--r--Duplicati/CommandLine/RecoveryTool/Restore.cs201
1 files changed, 101 insertions, 100 deletions
diff --git a/Duplicati/CommandLine/RecoveryTool/Restore.cs b/Duplicati/CommandLine/RecoveryTool/Restore.cs
index 734565b5b..92d147419 100644
--- a/Duplicati/CommandLine/RecoveryTool/Restore.cs
+++ b/Duplicati/CommandLine/RecoveryTool/Restore.cs
@@ -18,9 +18,9 @@ using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
-using Duplicati.Library.Common.IO;
-using Duplicati.Library.Common;
-
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Common;
+
namespace Duplicati.CommandLine.RecoveryTool
{
public static class Restore
@@ -105,138 +105,139 @@ namespace Duplicati.CommandLine.RecoveryTool
using (var mru = new CompressedFileMRUCache(options))
{
Console.WriteLine("Building lookup table for file hashes");
- var lookup = new HashLookupHelper(ixfile, mru, (int)blocksize, blockhasher.HashSize / 8);
-
- var filecount = 0L;
- string largestprefix = null;
- string[] largestprefixparts = null;
+ using (HashLookupHelper lookup = new HashLookupHelper(ixfile, mru, (int) blocksize, blockhasher.HashSize / 8))
+ {
+ var filecount = 0L;
+ string largestprefix = null;
+ string[] largestprefixparts = null;
- if (!string.IsNullOrWhiteSpace(targetpath))
- Console.WriteLine("Computing restore path");
+ if (!string.IsNullOrWhiteSpace(targetpath))
+ Console.WriteLine("Computing restore path");
- foreach (var f in List.EnumerateFilesInDList(filelist, filter, options))
- {
- if (largestprefix == null)
+ foreach (var f in List.EnumerateFilesInDList(filelist, filter, options))
{
- largestprefix = f.Path;
- largestprefixparts = largestprefix.Split(new char[] { Path.DirectorySeparatorChar });
- }
- else if (largestprefix.Length > 1)
- {
- var parts = f.Path.Split(new char[] { Path.DirectorySeparatorChar });
+ if (largestprefix == null)
+ {
+ largestprefix = f.Path;
+ largestprefixparts = largestprefix.Split(new char[] { Path.DirectorySeparatorChar });
+ }
+ else if (largestprefix.Length > 1)
+ {
+ var parts = f.Path.Split(new char[] { Path.DirectorySeparatorChar });
- var ni = 0;
- for (; ni < Math.Min(parts.Length, largestprefixparts.Length); ni++)
- if (!Library.Utility.Utility.ClientFilenameStringComparer.Equals(parts[ni], largestprefixparts[ni]))
- break;
+ var ni = 0;
+ for (; ni < Math.Min(parts.Length, largestprefixparts.Length); ni++)
+ if (!Library.Utility.Utility.ClientFilenameStringComparer.Equals(parts[ni], largestprefixparts[ni]))
+ break;
- if (ni != largestprefixparts.Length)
- {
- if (ni == 0)
+ if (ni != largestprefixparts.Length)
{
- largestprefixparts = new string[0];
- largestprefix = string.Empty;
- }
- else
- {
- Array.Resize(ref largestprefixparts, ni - 1);
- largestprefix = string.Join(Util.DirectorySeparatorString, largestprefixparts);
+ if (ni == 0)
+ {
+ largestprefixparts = new string[0];
+ largestprefix = string.Empty;
+ }
+ else
+ {
+ Array.Resize(ref largestprefixparts, ni - 1);
+ largestprefix = string.Join(Util.DirectorySeparatorString, largestprefixparts);
+ }
}
}
+ filecount++;
}
- filecount++;
- }
- Console.WriteLine("Restoring {0} files to {1}", filecount, string.IsNullOrWhiteSpace(targetpath) ? "original position" : targetpath);
+ Console.WriteLine("Restoring {0} files to {1}", filecount, string.IsNullOrWhiteSpace(targetpath) ? "original position" : targetpath);
- if (Platform.IsClientPosix || largestprefix.Length > 0)
- largestprefix = Util.AppendDirSeparator(largestprefix);
+ if (Platform.IsClientPosix || largestprefix.Length > 0)
+ largestprefix = Util.AppendDirSeparator(largestprefix);
- if (!string.IsNullOrEmpty(largestprefix))
- Console.WriteLine("Removing common prefix {0} from files", largestprefix);
+ if (!string.IsNullOrEmpty(largestprefix))
+ Console.WriteLine("Removing common prefix {0} from files", largestprefix);
- var i = 0L;
- foreach (var f in List.EnumerateFilesInDList(filelist, filter, options))
- {
- try
+ var i = 0L;
+ foreach (var f in List.EnumerateFilesInDList(filelist, filter, options))
{
- var targetfile = MapToRestorePath(f.Path, largestprefix, targetpath);
- if (!Directory.Exists(Path.GetDirectoryName(targetfile)))
- Directory.CreateDirectory(Path.GetDirectoryName(targetfile));
+ try
+ {
+ var targetfile = MapToRestorePath(f.Path, largestprefix, targetpath);
+ if (!Directory.Exists(Path.GetDirectoryName(targetfile)))
+ Directory.CreateDirectory(Path.GetDirectoryName(targetfile));
- Console.Write("{0}: {1} ({2})", i, targetfile, Library.Utility.Utility.FormatSizeString(f.Size));
+ Console.Write("{0}: {1} ({2})", i, targetfile, Library.Utility.Utility.FormatSizeString(f.Size));
- using (var tf = new Library.Utility.TempFile())
- {
- using (var sw = File.OpenWrite(tf))
+ using (var tf = new Library.Utility.TempFile())
{
- if (f.BlocklistHashes == null)
- {
- lookup.WriteHash(sw, f.Hash);
- }
- else
+ using (var sw = File.OpenWrite(tf))
{
- var blhi = 0L;
- foreach (var blh in f.BlocklistHashes)
+ if (f.BlocklistHashes == null)
{
- Console.Write(" {0}", blhi);
- var blockhashoffset = blhi * hashesprblock * blocksize;
-
- try
+ lookup.WriteHash(sw, f.Hash);
+ }
+ else
+ {
+ var blhi = 0L;
+ foreach (var blh in f.BlocklistHashes)
{
- var bi = 0;
- foreach (var h in lookup.ReadBlocklistHashes(blh))
+ Console.Write(" {0}", blhi);
+ var blockhashoffset = blhi * hashesprblock * blocksize;
+
+ try
{
- try
- {
- sw.Position = blockhashoffset + (bi * blocksize);
- lookup.WriteHash(sw, h);
- }
- catch (Exception ex)
+ var bi = 0;
+ foreach (var h in lookup.ReadBlocklistHashes(blh))
{
- Console.WriteLine("Failed to read hash: {0}{1}{2}", h, Environment.NewLine, ex);
+ try
+ {
+ sw.Position = blockhashoffset + (bi * blocksize);
+ lookup.WriteHash(sw, h);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Failed to read hash: {0}{1}{2}", h, Environment.NewLine, ex);
+ }
+
+ bi++;
}
-
- bi++;
}
- }
- catch (Exception ex)
- {
- Console.WriteLine("Failed to read Blocklist hash: {0}{1}{2}", blh, Environment.NewLine, ex);
- }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Failed to read Blocklist hash: {0}{1}{2}", blh, Environment.NewLine, ex);
+ }
- blhi++;
+ blhi++;
+ }
}
}
- }
- string fh;
- using (var fs = File.OpenRead(tf))
- fh = Convert.ToBase64String(filehasher.ComputeHash(fs));
+ string fh;
+ using (var fs = File.OpenRead(tf))
+ fh = Convert.ToBase64String(filehasher.ComputeHash(fs));
- if (fh == f.Hash)
- {
- Console.WriteLine(" done!");
- File.Copy(tf, targetfile, true);
- }
- else
- {
- Console.Write(" - Restored file hash mismatch");
- if (File.Exists(targetfile))
- Console.WriteLine(" - not overwriting existing file: {0}", targetfile);
+ if (fh == f.Hash)
+ {
+ Console.WriteLine(" done!");
+ File.Copy(tf, targetfile, true);
+ }
else
- Console.WriteLine(" - restoring file in damaged condition");
+ {
+ Console.Write(" - Restored file hash mismatch");
+ if (File.Exists(targetfile))
+ Console.WriteLine(" - not overwriting existing file: {0}", targetfile);
+ else
+ Console.WriteLine(" - restoring file in damaged condition");
+ }
}
- }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(" error: {0}", ex);
+ }
+ i++;
}
- catch (Exception ex)
- {
- Console.WriteLine(" error: {0}", ex);
- }
- i++;
}
}