wrap UpdateOldVersion/UpdateVersionNumber in a transaction to ensure both are complet...
authorJonathan Marshall <jmarshall@never.you.mind>
Tue, 24 Apr 2012 05:22:44 +0000 (17:22 +1200)
committerJonathan Marshall <jmarshall@never.you.mind>
Sun, 8 Jul 2012 02:34:14 +0000 (14:34 +1200)
xbmc/dbwrappers/Database.cpp

index c8d9f78..448d1c9 100644 (file)
@@ -452,13 +452,27 @@ bool CDatabase::UpdateVersion(const CStdString &dbName)
   if (version < GetMinVersion())
   {
     CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", dbName.c_str(), version, GetMinVersion());
-    if (UpdateOldVersion(version) && UpdateVersionNumber())
-      CLog::Log(LOGINFO, "Update to version %i successfull", GetMinVersion());
-    else
+    bool success = false;
+    BeginTransaction();
+    try
+    {
+      success = UpdateOldVersion(version);
+      if (success)
+        success = UpdateVersionNumber();
+    }
+    catch (...)
     {
-      CLog::Log(LOGERROR, "Can't update the database %s from version %i to %i", dbName.c_str(), version, GetMinVersion());
+      CLog::Log(LOGERROR, "Exception updating database %s from version %i to %i", dbName.c_str(), version, GetMinVersion());
+      success = false;
+    }
+    if (!success)
+    {
+      CLog::Log(LOGERROR, "Error updating database %s from version %i to %i", dbName.c_str(), version, GetMinVersion());
+      RollbackTransaction();
       return false;
     }
+    CommitTransaction();
+    CLog::Log(LOGINFO, "Update to version %i successful", GetMinVersion());
   }
   else if (version > GetMinVersion())
   {