changeset 1252:9a482182f80f

(issue54) Monitor update installation and restart afterwards on Linux
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 25 Sep 2014 15:57:25 +0200
parents 3b433a350092
children eb4d7337edd7
files packaging/linux-installer.l10n-de ui/mainwindow.cpp ui/mainwindow.h
diffstat 3 files changed, 47 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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"
 )
--- 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)
--- 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();

http://wald.intevation.org/projects/trustbridge/