summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/elevatedexecuteoperation.cpp
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2021-01-22 14:50:16 +0200
committerKatja Marttila <katja.marttila@qt.io>2021-02-05 09:07:04 +0200
commit5aee36b74eb1d7613ea0108971e8a22f8dca8101 (patch)
tree30842cc3b88483c18facd2510ed7c5e3d0a0f138 /src/libs/installer/elevatedexecuteoperation.cpp
parenta7b0eead83379d9343429a37efa8e39f924e8525 (diff)
Try rerunning execute operation
Execute operation can have hard coded paths to program which is executed. In case the program is relocated, UNDO operation will fail as it will not find the program. Implemented new XXXX_OLD value which can be used for overwriting the hardcoded value. In case the program execution fails, program is tried to launch again with the replaced value. Task-number: QTIFW-2125 Change-Id: I446a4c423e53cc4ffc6e5e25617d2400945ac3d9 Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'src/libs/installer/elevatedexecuteoperation.cpp')
-rw-r--r--src/libs/installer/elevatedexecuteoperation.cpp85
1 files changed, 64 insertions, 21 deletions
diff --git a/src/libs/installer/elevatedexecuteoperation.cpp b/src/libs/installer/elevatedexecuteoperation.cpp
index 39be98e6f..f81377ac4 100644
--- a/src/libs/installer/elevatedexecuteoperation.cpp
+++ b/src/libs/installer/elevatedexecuteoperation.cpp
@@ -61,7 +61,11 @@ private:
public:
void readProcessOutput();
- bool run(const QStringList &arguments);
+ int run(QStringList &arguments, const OperationType type);
+
+private:
+ bool needsRerunWithReplacedVariables(QStringList &arguments, const OperationType type);
+
QProcessWrapper *process;
bool showStandardError;
@@ -100,10 +104,10 @@ bool ElevatedExecuteOperation::performOperation()
PackageManagerCore *const core = packageManager();
args = core->replaceVariables(args);
}
- return d->run(args);
+ return d->run(args, Operation::Perform) ? false : true;
}
-bool ElevatedExecuteOperation::Private::run(const QStringList &arguments)
+int ElevatedExecuteOperation::Private::run(QStringList &arguments, const OperationType type)
{
QStringList args = arguments;
QString workingDirectory;
@@ -192,13 +196,17 @@ bool ElevatedExecuteOperation::Private::run(const QStringList &arguments)
success = process->waitForFinished(-1);
}
- bool returnValue = true;
+ int returnValue = NoError;
if (!success) {
q->setError(UserDefinedError);
//TODO: pass errorString() through the wrapper */
q->setErrorString(tr("Cannot start: \"%1\": %2").arg(callstr,
process->errorString()));
- returnValue = false;
+ if (!needsRerunWithReplacedVariables(arguments, type)) {
+ returnValue = Error;
+ } else {
+ returnValue = NeedsRerun;
+ }
}
if (QThread::currentThread() == qApp->thread()) {
@@ -213,26 +221,29 @@ bool ElevatedExecuteOperation::Private::run(const QStringList &arguments)
if (process->exitStatus() == QProcessWrapper::CrashExit) {
q->setError(UserDefinedError);
q->setErrorString(tr("Program crashed: \"%1\"").arg(callstr));
- returnValue = false;
+ returnValue = Error;
}
- if (!allowedExitCodes.contains(process->exitCode())) {
- q->setError(UserDefinedError);
- if (customErrorMessage.isEmpty()) {
- q->setErrorString(tr("Execution failed (Unexpected exit code: %1): \"%2\"")
- .arg(QString::number(process->exitCode()), callstr));
+ if (!allowedExitCodes.contains(process->exitCode()) && returnValue != NeedsRerun) {
+ if (!needsRerunWithReplacedVariables(arguments, type)) {
+ q->setError(UserDefinedError);
+ if (customErrorMessage.isEmpty()) {
+ q->setErrorString(tr("Execution failed (Unexpected exit code: %1): \"%2\"")
+ .arg(QString::number(process->exitCode()), callstr));
+ } else {
+ q->setErrorString(customErrorMessage);
+ }
+
+ QByteArray standardErrorOutput = process->readAllStandardError();
+ // in error case it would be useful to see something in verbose output
+ if (!standardErrorOutput.isEmpty())
+ qCWarning(QInstaller::lcInstallerInstallLog).noquote() << standardErrorOutput;
+
+ returnValue = Error;
} else {
- q->setErrorString(customErrorMessage);
+ returnValue = NeedsRerun;
}
-
- QByteArray standardErrorOutput = process->readAllStandardError();
- // in error case it would be useful to see something in verbose output
- if (!standardErrorOutput.isEmpty())
- qCWarning(QInstaller::lcInstallerInstallLog).noquote() << standardErrorOutput;
-
- returnValue = false;
}
-
Q_ASSERT(process);
Q_ASSERT(process->state() == QProcessWrapper::NotRunning);
delete process;
@@ -241,6 +252,28 @@ bool ElevatedExecuteOperation::Private::run(const QStringList &arguments)
return returnValue;
}
+bool ElevatedExecuteOperation::Private::needsRerunWithReplacedVariables(QStringList &arguments, const OperationType type)
+{
+ if (type != Operation::Undo)
+ return false;
+ bool rerun = false;
+ PackageManagerCore *const core = q->packageManager();
+ for (int i = 0; i < arguments.count(); i++) {
+ QString key = core->key(arguments.at(i));
+ if (!key.isEmpty() && key.endsWith(QLatin1String("_OLD"))) {
+ key.remove(key.length() - 4, 4);
+ if (core->containsValue(key)) {
+ key.prepend(QLatin1String("@"));
+ key.append(QLatin1String("@"));
+ QString value = core->replaceVariables(key);
+ arguments.replace(i, value);
+ rerun = true;
+ }
+ }
+ }
+ return rerun;
+}
+
/*!
Cancels the ElevatedExecuteOperation. This methods tries to terminate the process
gracefully by calling QProcessWrapper::terminate. After 10 seconds, the process gets killed.
@@ -285,7 +318,17 @@ bool ElevatedExecuteOperation::undoOperation()
PackageManagerCore *const core = packageManager();
args = core->replaceVariables(args);
}
- return d->run(args);
+
+ int returnValue = d->run(args, Operation::Undo);
+ if (returnValue == NeedsRerun) {
+ qCDebug(QInstaller::lcInstallerInstallLog).noquote() << QString::fromLatin1("Failed to run "
+ "undo operation \"%1\" for component %2. Trying again with arguments %3").arg(name(),
+ value(QLatin1String("component")).toString(), args.join(QLatin1String(", ")));
+ setError(NoError);
+ setErrorString(QString());
+ returnValue = d->run(args, Operation::Undo);
+ }
+ return returnValue ? false : true;
}
bool ElevatedExecuteOperation::testOperation()