From 41b1a5ad4aafd43bfc1c9e60755d981df2f181c8 Mon Sep 17 00:00:00 2001 From: "kenneth.skovhede@gmail.com" Date: Sat, 22 Oct 2011 14:55:06 +0000 Subject: [PATCH] Added a protection against partial downloads git-svn-id: https://duplicati.googlecode.com/svn/trunk@941 59da171f-624f-0410-aa54-27559c288bec --- Duplicati/CommandLine/BackendTester/Program.cs | 4 ++++ Duplicati/Library/Main/BackendWrapper.cs | 5 +++++ .../Library/Main/Strings/BackendWrapper.Designer.cs | 11 ++++++++++- Duplicati/Library/Main/Strings/BackendWrapper.resx | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Duplicati/CommandLine/BackendTester/Program.cs b/Duplicati/CommandLine/BackendTester/Program.cs index 244fc0a8d..01ab1cd31 100644 --- a/Duplicati/CommandLine/BackendTester/Program.cs +++ b/Duplicati/CommandLine/BackendTester/Program.cs @@ -249,6 +249,10 @@ namespace Duplicati.CommandLine.BackendTester Console.WriteLine("*** File with name {0} was found more than once", tx.filename); found = true; tx.found = true; + + if (fe.Size > 0 && tx.length != fe.Size) + Console.WriteLine("*** File with name {0} has size {1} but the size was reported as {2}", tx.filename, tx.length, fe.Size); + break; } diff --git a/Duplicati/Library/Main/BackendWrapper.cs b/Duplicati/Library/Main/BackendWrapper.cs index 17ad240cb..e6af7aeca 100644 --- a/Duplicati/Library/Main/BackendWrapper.cs +++ b/Duplicati/Library/Main/BackendWrapper.cs @@ -960,6 +960,11 @@ namespace Duplicati.Library.Main ProgressEvent(100, m_statusmessage); } + //This is required so we are sure that the file was downloaded completely and not partially, + // as any exception here will cause a retry, but using a partial file may cause random errors + if (remote.Fileentry.Size > 0 && remote.Fileentry.Size != new System.IO.FileInfo(tempfile).Length) + throw new Exception(string.Format(Strings.BackendWrapper.DownloadedFileSizeError, remote.Filename, remote.Fileentry.Size, new System.IO.FileInfo(tempfile).Length)); + remote.RemoteHash = Utility.Utility.CalculateHash(tempfile); //Manifest version 3 has hashes WITH encryption diff --git a/Duplicati/Library/Main/Strings/BackendWrapper.Designer.cs b/Duplicati/Library/Main/Strings/BackendWrapper.Designer.cs index 0e6c0ef31..a7ae645aa 100644 --- a/Duplicati/Library/Main/Strings/BackendWrapper.Designer.cs +++ b/Duplicati/Library/Main/Strings/BackendWrapper.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.237 +// Runtime Version:4.0.30319.239 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -105,6 +105,15 @@ namespace Duplicati.Library.Main.Strings { } } + /// + /// Looks up a localized string similar to The file {0} was downloaded and had size {1} but the size was expected to be {2}. + /// + internal static string DownloadedFileSizeError { + get { + return ResourceManager.GetString("DownloadedFileSizeError", resourceCulture); + } + } + /// /// Looks up a localized string similar to The file {0} was found multiple times in the file list, this is likely an error in the backend, please report it to the developers. /// diff --git a/Duplicati/Library/Main/Strings/BackendWrapper.resx b/Duplicati/Library/Main/Strings/BackendWrapper.resx index 87f45b57e..f04f98dda 100644 --- a/Duplicati/Library/Main/Strings/BackendWrapper.resx +++ b/Duplicati/Library/Main/Strings/BackendWrapper.resx @@ -204,4 +204,7 @@ An error occured while closing a connection: {0} + + The file {0} was downloaded and had size {1} but the size was expected to be {2} + \ No newline at end of file