diff --git a/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp b/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp index 6969647aa8..c0b1cd14a0 100644 --- a/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp +++ b/src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp @@ -123,10 +123,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)); @@ -148,8 +149,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)) { @@ -160,12 +160,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; } } @@ -227,7 +227,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" @@ -242,7 +242,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)); @@ -277,7 +277,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; } @@ -297,7 +297,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; } diff --git a/src/settings/services/test/service_menu_deinstallation_test.rb b/src/settings/services/test/service_menu_deinstallation_test.rb index 1c9856d948..4017e8ee07 100644 --- a/src/settings/services/test/service_menu_deinstallation_test.rb +++ b/src/settings/services/test/service_menu_deinstallation_test.rb @@ -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