]> cloud.milkyroute.net Git - dolphin.git/commitdiff
servicemenuinstaller: Run installation scripts with cwd in their parent directories
authorAlexander Potashev <aspotashev@gmail.com>
Mon, 15 Jul 2019 19:17:03 +0000 (22:17 +0300)
committerAlexander Potashev <aspotashev@gmail.com>
Tue, 16 Jul 2019 12:04:54 +0000 (15:04 +0300)
Summary:
Otherwise, if cwd is set to the unpacked dir root, some service menus
fail to install.

Test Plan:
 - Successfully Installed and uninstalled the "Color Folder" service menu from "Configure Dolphin..." -> service menus -> KNewStuff.
 - ./test_run.rb still passes all its tests.

Reviewers: elvisangelaccio, sitter

Reviewed By: sitter

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D22466

src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp
src/settings/services/test/service_menu_deinstallation_test.rb

index 9c614a8d31d12428b820278d664e9b6c99eedb2f..c06a71c23741d6e04646d4acf0e1c3c213d48e67 100644 (file)
@@ -157,10 +157,11 @@ QString findRecursive(const QString &dir, const QString &basename)
     return QString();
 }
 
-bool runInstallerScriptOnce(const QString &path, const QStringList &args, const QString &dir)
+bool runInstallerScriptOnce(const QString &path, const QStringList &args)
 {
     QProcess process;
-    process.setWorkingDirectory(dir);
+    process.setWorkingDirectory(QFileInfo(path).absolutePath());
+
     process.start(path, args, QIODevice::NotOpen);
     if (!process.waitForStarted()) {
         fail(i18n("Failed to run installer script %1", path));
@@ -182,8 +183,7 @@ bool runInstallerScriptOnce(const QString &path, const QStringList &args, const
 
 // If hasArgVariants is true, run "path".
 // If hasArgVariants is false, run "path argVariants[i]" until successful.
-bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringList &argVariants, const QString &dir,
-    QString &errorText)
+bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringList &argVariants, QString &errorText)
 {
     QFile file(path);
     if (!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) {
@@ -194,12 +194,12 @@ bool runInstallerScript(const QString &path, bool hasArgVariants, const QStringL
     qInfo() << "[servicemenuinstaller]: Trying to run installer/uninstaller" << path;
     if (hasArgVariants) {
         for (const auto &arg : argVariants) {
-            if (runInstallerScriptOnce(path, QStringList{arg}, dir)) {
+            if (runInstallerScriptOnce(path, QStringList{arg})) {
                 return true;
             }
         }
     } else {
-        if (runInstallerScriptOnce(path, QStringList{}, dir)) {
+        if (runInstallerScriptOnce(path, QStringList{})) {
             return true;
         }
     }
@@ -261,7 +261,7 @@ bool cmdInstall(const QString &archive, QString &errorText)
         }
 
         if (!installItPath.isEmpty()) {
-            return runInstallerScript(installItPath, false, QStringList{}, dir, errorText);
+            return runInstallerScript(installItPath, false, QStringList{}, errorText);
         }
 
         // If "install-it" is missing, try "install"
@@ -276,7 +276,7 @@ bool cmdInstall(const QString &archive, QString &errorText)
         }
 
         if (!installerPath.isEmpty()) {
-            return runInstallerScript(installerPath, true, QStringList{"--local", "--local-install", "--install"}, dir, errorText);
+            return runInstallerScript(installerPath, true, QStringList{"--local", "--local-install", "--install"}, errorText);
         }
 
         fail(i18n("Failed to find an installation script in %1", dir));
@@ -311,7 +311,7 @@ bool cmdUninstall(const QString &archive, QString &errorText)
         }
 
         if (!deinstallPath.isEmpty()) {
-            bool ok = runInstallerScript(deinstallPath, false, QStringList{}, dir, errorText);
+            bool ok = runInstallerScript(deinstallPath, false, QStringList{}, errorText);
             if (!ok) {
                 return ok;
             }
@@ -331,7 +331,7 @@ bool cmdUninstall(const QString &archive, QString &errorText)
 
             if (!installerPath.isEmpty()) {
                 bool ok = runInstallerScript(
-                    installerPath, true, QStringList{"--remove", "--delete", "--uninstall", "--deinstall"}, dir, errorText);
+                    installerPath, true, QStringList{"--remove", "--delete", "--uninstall", "--deinstall"}, errorText);
                 if (!ok) {
                     return ok;
                 }
index 1c9856d948b5d47fbcbbf0e963bf3a272a0c24f6..4017e8ee0730db87ba75d54ef86b744a0f02518c 100644 (file)
@@ -44,10 +44,14 @@ class ServiceMenuDeinstallationTest < Test::Unit::TestCase
     FileUtils.mkpath(archive_dir)
     File.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH)
 #!/bin/sh
+set -e
+cat deinstall.sh
 touch #{@tmpdir}/deinstall.sh-run
     DEINSTALL_SH
     File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
 #!/bin/sh
+set -e
+cat install.sh
 touch #{@tmpdir}/install.sh-run
     INSTALL_SH