From 97318e602acaaef57e5cde3e992f6669ea491012 Mon Sep 17 00:00:00 2001 From: "kenneth.skovhede@gmail.com" Date: Sat, 23 Oct 2010 09:09:14 +0000 Subject: [PATCH] Update issue #163 Status: Fixed There is now an error message and a helpful rollback message displayed if the database version does not fit. git-svn-id: https://duplicati.googlecode.com/svn/trunk@557 59da171f-624f-0410-aa54-27559c288bec --- Duplicati/GUI/DatabaseUpgrader.cs | 5 +++++ .../GUI/Strings/DatabaseUpgrader.Designer.cs | 19 +++++++++++++++++-- Duplicati/GUI/Strings/DatabaseUpgrader.resx | 8 ++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Duplicati/GUI/DatabaseUpgrader.cs b/Duplicati/GUI/DatabaseUpgrader.cs index da58c0b08..878ca6880 100644 --- a/Duplicati/GUI/DatabaseUpgrader.cs +++ b/Duplicati/GUI/DatabaseUpgrader.cs @@ -109,6 +109,7 @@ namespace Duplicati.GUI //ea, from 1 to 8, by stepping 2->3->4->5->6->7->8 SortedDictionary upgrades = new SortedDictionary(); string prefix = typeof(DatabaseUpgrader).Namespace + "." + FOLDER_NAME + "."; + int maxversion = -1; foreach (string s in asm.GetManifestResourceNames()) { //The resource name will be "Duplicati.GUI.Database_schema.1.Sample upgrade.sql" @@ -119,6 +120,7 @@ namespace Duplicati.GUI { string version = s.Substring(prefix.Length, s.IndexOf(".", prefix.Length + 1) - prefix.Length); int fileversion = int.Parse(version); + maxversion = Math.Max(maxversion, fileversion); if (fileversion > dbversion) { if (!upgrades.ContainsKey(fileversion)) @@ -132,6 +134,9 @@ namespace Duplicati.GUI } } + if (dbversion > maxversion) + throw new Exception(string.Format(Strings.DatabaseUpgrader.InvalidVersionError, dbversion, maxversion, System.IO.Path.GetDirectoryName(sourcefile))); + if (upgrades.Count > 0) { string backupfile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourcefile), Strings.DatabaseUpgrader.BackupFilenamePrefix + " " + DateTime.Now.ToString("yyyyMMddhhmmss") + ".sqlite"); diff --git a/Duplicati/GUI/Strings/DatabaseUpgrader.Designer.cs b/Duplicati/GUI/Strings/DatabaseUpgrader.Designer.cs index 31217ef6e..8f53d94dd 100644 --- a/Duplicati/GUI/Strings/DatabaseUpgrader.Designer.cs +++ b/Duplicati/GUI/Strings/DatabaseUpgrader.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.3082 +// Runtime Version:2.0.50727.4952 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -78,6 +78,19 @@ namespace Duplicati.GUI.Strings { } } + /// + /// Looks up a localized string similar to + ///The database has version {0} but the largest supported version is {1}. + /// + ///This is likely caused by upgrading to a newer version and then downgrading. + ///If this is the case, there is likely a backup file of the previous database version in the folder {2}.. + /// + internal static string InvalidVersionError { + get { + return ResourceManager.GetString("InvalidVersionError", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unknown table layout detected. /// @@ -88,7 +101,9 @@ namespace Duplicati.GUI.Strings { } /// - /// Looks up a localized string similar to Failed to execute SQL: {0}\nError: {1}\nDatabase is NOT upgraded.. + /// Looks up a localized string similar to Failed to execute SQL: {0} + ///Error: {1} + ///Database is NOT upgraded.. /// internal static string UpgradeFailure { get { diff --git a/Duplicati/GUI/Strings/DatabaseUpgrader.resx b/Duplicati/GUI/Strings/DatabaseUpgrader.resx index 52b008a35..9a48a0514 100644 --- a/Duplicati/GUI/Strings/DatabaseUpgrader.resx +++ b/Duplicati/GUI/Strings/DatabaseUpgrader.resx @@ -125,6 +125,14 @@ Unable to determine database format: {0} An error message that is displayed if an error occurs while determining database layout + + +The database has version {0} but the largest supported version is {1}. + +This is likely caused by upgrading to a newer version and then downgrading. +If this is the case, there is likely a backup file of the previous database version in the folder {2}. + An error message that is displayed if the database version number does not match + Unknown table layout detected An error message that is displayed when the layout of the database is unexpected