[PATCH 3 of 3] (issue54) Monitor update installation and restart afterwards on Linux

Wald Commits scm-commit at wald.intevation.org
Thu Sep 25 15:57:32 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1411653445 -7200
# Node ID 9a482182f80ffdc95d98fd27c24eee6e04812735
# Parent  3b433a3500929361f99d91453ef692ece7a9547a
(issue54) Monitor update installation and restart afterwards on Linux

diff -r 3b433a350092 -r 9a482182f80f packaging/linux-installer.l10n-de
--- a/packaging/linux-installer.l10n-de	Thu Sep 25 15:56:37 2014 +0200
+++ b/packaging/linux-installer.l10n-de	Thu Sep 25 15:57:25 2014 +0200
@@ -46,4 +46,5 @@
   ["the installation directory will be containing these characters verbatim.\n\n"]="der Installations-Pfad wird diese Zeichen unverändert enthalten.\n\n"
   ["to update the current installation.\n"]="um die vorhandene Installation zu aktualisieren.\n"
   ["unpacking files ...\n"]="Entpacke Dateien ...\n"
+  ["You can now launch '%s'\n"]="Sie können nun '%s' starten\n"
 )
diff -r 3b433a350092 -r 9a482182f80f ui/mainwindow.cpp
--- a/ui/mainwindow.cpp	Thu Sep 25 15:56:37 2014 +0200
+++ b/ui/mainwindow.cpp	Thu Sep 25 15:57:25 2014 +0200
@@ -342,6 +342,23 @@
     return targetPath;
 }
 
+void MainWindow::updaterFinished(int exitCode, QProcess::ExitStatus status)
+{
+    if (status != QProcess::NormalExit) {
+        syslog_error_printf("Update failed.\n");
+        qDebug() << "Failed to install update.";
+        return;
+    }
+    if (exitCode != 0) {
+        qDebug() << "Update not installed with error: " << exitCode;
+        return;
+    }
+    qDebug() << "Restarting";
+    ProcessHelp::cleanUp();
+    QProcess::startDetached(qApp->applicationFilePath());
+    qApp->quit();
+}
+
 void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) {
     QFileInfo instProcInfo = QFileInfo(fileName);
     QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
@@ -410,26 +427,44 @@
     parameters << "--update";
     bool sudo_started = false;
     bool use_sudo = is_admin() && is_system_install();
+
+    QProcess *updaterProcess = new QProcess();
+
     if (use_sudo) {
         QStringList sudoPrograms;
         sudoPrograms << "pkexec" << "kdesudo" << "sudo";
         QStringList sudoParams;
-        sudoParams << filePath + " " + parameters.join(" ");
+        sudoParams << filePath;
+        sudoParams << parameters;
+        updaterProcess->setArguments(sudoParams);
 
         foreach (const QString &sProg, sudoPrograms) {
             qDebug() << "Starting process " << sProg <<" params: " << sudoParams;
-            if (!QProcess::startDetached(sProg, sudoParams)) {
+            updaterProcess->setProgram(sProg);
+            updaterProcess->start();
+            if (!updaterProcess->waitForStarted() ||
+                updaterProcess->state() == QProcess::NotRunning) {
                 continue;
             } else {
                 sudo_started = true;
+                connect(updaterProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
+                        this, SLOT(updaterFinished(int, QProcess::ExitStatus)));
                 break;
             }
         }
     }
-    qDebug() << "Starting process " << filePath <<" params: " << parameters;
-    if (!sudo_started && !QProcess::startDetached(filePath, parameters)) {
-        qDebug() << "Failed to start process.";
-        fclose(vres.fptr);
+    if (!sudo_started) {
+        qDebug() << "Starting process " << filePath <<" params: " << parameters;
+        updaterProcess->setArguments(parameters);
+        updaterProcess->setProgram(filePath);
+        updaterProcess->start();
+
+        if (!updaterProcess->waitForStarted() ||
+            updaterProcess->state() == QProcess::NotRunning) {
+            qDebug() << "Failed to start process.";
+        }
+        connect(updaterProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
+                this, SLOT(restart()));
         return;
     }
 
@@ -442,7 +477,9 @@
     syslog_info_printf ("Installing update: %s\n", fileName.toUtf8().constData());
     /* Installer process should now be running. We exit */
     fclose(vres.fptr);
+#ifdef WIN32
     closeApp();
+#endif
 }
 
 void MainWindow::checkUpdates(bool downloadSW)
diff -r 3b433a350092 -r 9a482182f80f ui/mainwindow.h
--- a/ui/mainwindow.h	Thu Sep 25 15:56:37 2014 +0200
+++ b/ui/mainwindow.h	Thu Sep 25 15:57:25 2014 +0200
@@ -22,6 +22,7 @@
 #include <QLabel>
 #include <QCheckBox>
 #include <QScrollArea>
+#include <QProcess>
 
 #include "downloader.h"
 #include "certificatelist.h"
@@ -119,6 +120,8 @@
     void toggleInManual(bool state, const Certificate &cert);
     /** @brief Remove a certificate from the manual list. */
     void removeFromManual(bool state, const Certificate &cert);
+    /** @brief Restart the application */
+    void updaterFinished(int exitCode, QProcess::ExitStatus status);
 
     void togglePages(int button);
     void toggleUpdatesNew();


More information about the Trustbridge-commits mailing list