From a568b1e55e601a2ec37eb069c2bca09e077aef89 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Wed, 30 Mar 2016 01:30:51 +0200 Subject: [PATCH] Fixed query and logic for issue reported in #1644 and #1583 --- Duplicati/Library/Main/Database/LocalDatabase.cs | 12 ++++-------- .../Library/Main/Operation/FilelistProcessor.cs | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Duplicati/Library/Main/Database/LocalDatabase.cs b/Duplicati/Library/Main/Database/LocalDatabase.cs index ea0ced7f9..329090b54 100644 --- a/Duplicati/Library/Main/Database/LocalDatabase.cs +++ b/Duplicati/Library/Main/Database/LocalDatabase.cs @@ -112,7 +112,7 @@ namespace Duplicati.Library.Main.Database m_selectremotevolumesCommand.CommandText = @"SELECT ""Name"", ""Type"", ""Size"", ""Hash"", ""State"", ""DeleteGraceTime"" FROM ""Remotevolume"""; - m_selectduplicateRemoteVolumesCommand.CommandText = string.Format(@"SELECT ID FROM ""Remotevolume"" WHERE ""Name"" IN (SELECT ""Name"" FROM ""Remotevolume"" WHERE ""State"" IN (""{0}"", ""{1}"")) AND NOT ""State"" IN (""{0}"", ""{1}"")", RemoteVolumeState.Deleted.ToString(), RemoteVolumeState.Deleting.ToString()); + m_selectduplicateRemoteVolumesCommand.CommandText = string.Format(@"SELECT DISTINCT ""Name"", ""State"" FROM ""Remotevolume"" WHERE ""Name"" IN (SELECT ""Name"" FROM ""Remotevolume"" WHERE ""State"" IN (""{0}"", ""{1}"")) AND NOT ""State"" IN (""{0}"", ""{1}"")", RemoteVolumeState.Deleted.ToString(), RemoteVolumeState.Deleting.ToString()); m_selectremotevolumeCommand.CommandText = @"SELECT ""Type"", ""Size"", ""Hash"", ""State"" FROM ""Remotevolume"" WHERE ""Name"" = ?"; m_selectremotevolumeCommand.AddParameter(); @@ -280,17 +280,13 @@ namespace Duplicati.Library.Main.Database return false; } - public IEnumerable DuplicateRemoteVolumes() + public IEnumerable> DuplicateRemoteVolumes() { foreach(var rd in m_selectduplicateRemoteVolumesCommand.ExecuteReaderEnumerable(null)) { - yield return new RemoteVolumeEntry( + yield return new KeyValuePair( rd.GetValue(0).ToString(), - (rd.GetValue(3) == null || rd.GetValue(3) == DBNull.Value) ? null : rd.GetValue(3).ToString(), - rd.ConvertValueToInt64(2, -1), - (RemoteVolumeType)Enum.Parse(typeof(RemoteVolumeType), rd.GetValue(1).ToString()), - (RemoteVolumeState)Enum.Parse(typeof(RemoteVolumeState), rd.GetValue(4).ToString()), - new DateTime(rd.ConvertValueToInt64(5, 0), DateTimeKind.Utc) + (RemoteVolumeState)Enum.Parse(typeof(RemoteVolumeState), rd.GetValue(1).ToString()) ); } } diff --git a/Duplicati/Library/Main/Operation/FilelistProcessor.cs b/Duplicati/Library/Main/Operation/FilelistProcessor.cs index be877fb84..bf7756021 100644 --- a/Duplicati/Library/Main/Operation/FilelistProcessor.cs +++ b/Duplicati/Library/Main/Operation/FilelistProcessor.cs @@ -237,10 +237,10 @@ namespace Duplicati.Library.Main.Operation foreach(var e in database.DuplicateRemoteVolumes()) { - if (e.State == RemoteVolumeState.Uploading || e.State == RemoteVolumeState.Temporary) - database.UnlinkRemoteVolume(e.Name, e.State); + if (e.Value == RemoteVolumeState.Uploading || e.Value == RemoteVolumeState.Temporary) + database.UnlinkRemoteVolume(e.Key, e.Value); else - throw new Exception(string.Format("The remote volume {0} appears in the database with state {1} and a deleted state, cannot continue", e.Name, e.State.ToString())); + throw new Exception(string.Format("The remote volume {0} appears in the database with state {1} and a deleted state, cannot continue", e.Key, e.Value.ToString())); } var locallist = database.GetRemoteVolumes();