[PATCH 1 of 4] Delete old lists and rename the currently installed list to list-installed.txt

Wald Commits scm-commit at wald.intevation.org
Mon Aug 4 17:57:16 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1407157576 -7200
# Node ID 9bab4fc3a1fe318dd37808f61ba1ed486a380bb8
# Parent  797aa8d9c78531a3a38056ae5da32eb6ee15d751
Delete old lists and rename the currently installed list to list-installed.txt

diff -r 797aa8d9c785 -r 9bab4fc3a1fe ui/mainwindow.cpp
--- a/ui/mainwindow.cpp	Thu Jul 31 12:56:26 2014 +0200
+++ b/ui/mainwindow.cpp	Mon Aug 04 15:06:16 2014 +0200
@@ -29,6 +29,7 @@
 #include <QCheckBox>
 #include <QButtonGroup>
 #include <QToolButton>
+#include <QStandardPaths>
 
 #include "certificatelist.h"
 #include "downloader.h"
@@ -1068,11 +1069,44 @@
             qWarning() << "Error accessing settings";
             return; /* Try again with next check */
         }
+        /* Rename the installed list to list-installed.txt so that external
+         * programs (like the uninstaller can easily recognize it). */
+        QString dataLoc =
+            QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+        QDir dataDir(dataLoc);
+        if (!dataDir.exists()) {
+            /* Should not happen */
+            qWarning() << "Data dir removed.";
+            return;
+        }
 
-        mSettings.setValue("List/installed", listFileName);
+        QFileInfo oldList (dataDir.absoluteFilePath("list-installed.txt"));
+        if (oldList.exists()) {
+            qDebug() << "Removing old list: " << oldList.filePath();
+            if (!QFile::remove(oldList.filePath())) {
+                qWarning() << "Removal of old list failed.";
+                return;
+            }
+        }
+        QFile newList(listFileName);
+        if (!newList.rename(oldList.filePath())) {
+            qWarning() << "Failed to rename new list.";
+            return;
+        }
+
+        mSettings.setValue("List/installed", oldList.filePath());
         mSettings.setValue("List/installedDate", listFileDate);
-        mInstalledList = mListToInstall;
+        mInstalledList = CertificateList(oldList.filePath().toUtf8().constData());
+        if (!mInstalledList.isValid()) {
+            /* Something went wrong. Go back to square one. */
+            qWarning () << "List corrupted after installation";
+            mInstalledList = CertificateList();
+            QFile::remove(oldList.filePath());
+            mSettings.remove("List/installed");
+            mSettings.remove("List/installedDate");
+        }
         mListToInstall = CertificateList();
+
     }
     mUpdatesManual->clear();
     loadCertificateList();


More information about the Trustbridge-commits mailing list