summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2021-01-21 09:01:58 +0200
committerKatja Marttila <katja.marttila@qt.io>2021-02-03 22:17:42 +0200
commit3acc4e966025ea174fd873c4f29f76b6dfed9b4b (patch)
treee6ec29af9e81551ee476cb18ec19aad2808b3324 /src/libs
parent9792033524025e433e5537c4d9bc26531f6ae679 (diff)
Save Execute operation with predefined variable
When operations are saved to dat file, the variables are resolved making it impossible to change it afterwards. This change allows saving the Execute -operation variables unresolved. Variables are resolved runtime so those can be changed using e.g. script. Task-number: QTIFW-2124 Change-Id: I22a0502a5760234fc331aa931b8c66864e855e34 Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/installer/component.cpp10
-rw-r--r--src/libs/installer/elevatedexecuteoperation.cpp13
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp7
-rw-r--r--src/libs/kdtools/updateoperation.cpp20
-rw-r--r--src/libs/kdtools/updateoperation.h3
5 files changed, 47 insertions, 6 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp
index 4d614d242..2e797944b 100644
--- a/src/libs/installer/component.cpp
+++ b/src/libs/installer/component.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -1096,7 +1096,13 @@ Operation *Component::createOperation(const QString &operationName, const QStrin
if (operation->name() == QLatin1String("Delete"))
operation->setValue(QLatin1String("performUndo"), false);
- operation->setArguments(d->m_core->replaceVariables(parameters));
+ // Operation can contain variables which are resolved when performing the operation
+ if (operation->requiresUnreplacedVariables())
+ operation->setArguments(parameters);
+ else
+ operation->setArguments(d->m_core->replaceVariables(parameters));
+
+
operation->setValue(QLatin1String("component"), name());
return operation;
}
diff --git a/src/libs/installer/elevatedexecuteoperation.cpp b/src/libs/installer/elevatedexecuteoperation.cpp
index f5640ef8d..39be98e6f 100644
--- a/src/libs/installer/elevatedexecuteoperation.cpp
+++ b/src/libs/installer/elevatedexecuteoperation.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -31,6 +31,7 @@
#include "environment.h"
#include "qprocesswrapper.h"
#include "globals.h"
+#include "packagemanagercore.h"
#include <QtCore/QDebug>
#include <QtCore/QProcessEnvironment>
@@ -72,6 +73,7 @@ ElevatedExecuteOperation::ElevatedExecuteOperation(PackageManagerCore *core)
{
// this operation has to "overwrite" the Execute operation from KDUpdater
setName(QLatin1String("Execute"));
+ setRequiresUnreplacedVariables(true);
}
ElevatedExecuteOperation::~ElevatedExecuteOperation()
@@ -94,6 +96,10 @@ bool ElevatedExecuteOperation::performOperation()
break; //we don't need the UNDOEXECUTE args here
}
+ if (requiresUnreplacedVariables()) {
+ PackageManagerCore *const core = packageManager();
+ args = core->replaceVariables(args);
+ }
return d->run(args);
}
@@ -262,7 +268,6 @@ void ElevatedExecuteOperation::Private::readProcessOutput()
}
}
-
bool ElevatedExecuteOperation::undoOperation()
{
QStringList args;
@@ -276,6 +281,10 @@ bool ElevatedExecuteOperation::undoOperation()
if (args.isEmpty())
return true;
+ if (requiresUnreplacedVariables()) {
+ PackageManagerCore *const core = packageManager();
+ args = core->replaceVariables(args);
+ }
return d->run(args);
}
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index e3dfe7f4f..7f4330ca8 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -101,8 +101,11 @@ public:
return;
qCDebug(QInstaller::lcInstallerInstallLog).noquote() << QString::fromLatin1("%1 %2 operation: %3")
.arg(state, m_operation->value(QLatin1String("component")).toString(), m_operation->name());
+ QStringList args = m_operation->arguments();
+ if (m_operation->requiresUnreplacedVariables())
+ args = m_operation->packageManager()->replaceVariables(m_operation->arguments());
qCDebug(QInstaller::lcInstallerInstallLog).noquote() << QString::fromLatin1("\t- arguments: %1")
- .arg(m_operation->arguments().join(QLatin1String(", ")));
+ .arg(args.join(QLatin1String(", ")));
}
~OperationTracer() {
if (!m_operation)
diff --git a/src/libs/kdtools/updateoperation.cpp b/src/libs/kdtools/updateoperation.cpp
index 267cd8a80..35c9dce2e 100644
--- a/src/libs/kdtools/updateoperation.cpp
+++ b/src/libs/kdtools/updateoperation.cpp
@@ -89,6 +89,7 @@ static QString backupFileName(const QString &templateName)
UpdateOperation::UpdateOperation(QInstaller::PackageManagerCore *core)
: m_error(0)
, m_core(core)
+ , m_requiresUnreplacedVariables(false)
{
// Store the value for compatibility reasons.
m_values[QLatin1String("installer")] = QVariant::fromValue(core);
@@ -258,6 +259,16 @@ QStringList UpdateOperation::parseUndoOperationArguments()
return args;
}
+/*!
+ Sets the requirement for unresolved variables to \a isRequired.
+
+ \sa requiresUnreplacedVariables()
+*/
+void UpdateOperation::setRequiresUnreplacedVariables(bool isRequired)
+{
+ m_requiresUnreplacedVariables = isRequired;
+}
+
struct StartsWith
{
StartsWith(const QString &searchTerm)
@@ -354,6 +365,15 @@ QStringList UpdateOperation::filesForDelayedDeletion() const
}
/*!
+ Returns true if installer saves the variables unresolved.
+ The variables are resolved right before operation is performed.
+*/
+bool UpdateOperation::requiresUnreplacedVariables() const
+{
+ return m_requiresUnreplacedVariables;
+}
+
+/*!
Returns the package manager core this operation belongs to.
*/
QInstaller::PackageManagerCore *UpdateOperation::packageManager() const
diff --git a/src/libs/kdtools/updateoperation.h b/src/libs/kdtools/updateoperation.h
index b3642c78e..e05fc34d2 100644
--- a/src/libs/kdtools/updateoperation.h
+++ b/src/libs/kdtools/updateoperation.h
@@ -71,6 +71,7 @@ public:
QString errorString() const;
int error() const;
QStringList filesForDelayedDeletion() const;
+ bool requiresUnreplacedVariables() const;
QInstaller::PackageManagerCore *packageManager() const;
@@ -93,6 +94,7 @@ protected:
bool checkArgumentCount(int argCount);
QStringList parsePerformOperationArguments();
QStringList parseUndoOperationArguments();
+ void setRequiresUnreplacedVariables(bool isRequired);
private:
QString m_name;
@@ -102,6 +104,7 @@ private:
QVariantMap m_values;
QStringList m_delayedDeletionFiles;
QInstaller::PackageManagerCore *m_core;
+ bool m_requiresUnreplacedVariables;
};
} // namespace KDUpdater