summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-06-09 10:52:51 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-08-21 10:56:00 +0300
commitf2ab63396c1f101216b2c6ade37528492e464785 (patch)
tree6aeceb76196b453d8a999ddf2d4e8b0d1dc43aef
parent190b643736d7fa3270dca5926e018d6eef6d74cb (diff)
CLI: Ask user confirmation before performing installer actions
Also add new option --confirm-command to skip the interactive query. Task-number: QTIFW-1834 Change-Id: I1c63fd990431c792a523da7047637f54b193bee6 Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--src/libs/installer/commandlineparser.cpp2
-rw-r--r--src/libs/installer/constants.h1
-rw-r--r--src/libs/installer/packagemanagercore.cpp13
-rw-r--r--src/libs/installer/packagemanagercore.h2
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp31
-rw-r--r--src/libs/installer/packagemanagercore_p.h2
-rw-r--r--src/sdk/sdkapp.h3
-rw-r--r--tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp1
-rw-r--r--tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp1
-rw-r--r--tests/auto/installer/shared/packagemanager.h1
10 files changed, 51 insertions, 6 deletions
diff --git a/src/libs/installer/commandlineparser.cpp b/src/libs/installer/commandlineparser.cpp
index 051de2c1f..08aa1b3a9 100644
--- a/src/libs/installer/commandlineparser.cpp
+++ b/src/libs/installer/commandlineparser.cpp
@@ -172,6 +172,8 @@ CommandLineParser::CommandLineParser()
"Several identifier=value pairs can be given separated with comma, "
"for example --file-query filedialog.id=C:\Temp,filedialog.id2=C:\Temp2"),
QLatin1String("identifier=value")));
+ m_parser.addOption(QCommandLineOption(QStringList() << CommandLineOptions::scConfirmCommand,
+ QLatin1String("[CLI] Confirms starting of installation, update or removal of components without user input.")));
// Developer options
m_parser.addOption(QCommandLineOption(QStringList()
diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h
index c5d018bf4..27b9c08ee 100644
--- a/src/libs/installer/constants.h
+++ b/src/libs/installer/constants.h
@@ -160,6 +160,7 @@ static const QLatin1String scMessageAutomaticAnswer("auto-answer");
static const QLatin1String scMessageDefaultAnswer("default-answer");
static const QLatin1String scAcceptLicenses("accept-licenses");
static const QLatin1String scFileDialogAutomaticAnswer("file-query");
+static const QLatin1String scConfirmCommand("confirm-command");
// Misc installation options
static const QLatin1String scRootShort("t");
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 137627ae1..89b9b782c 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -685,6 +685,14 @@ QHash<QString, QString> PackageManagerCore::fileDialogAutomaticAnswers() const
}
/*!
+ Set to automatically confirm install, update or remove without asking user.
+*/
+void PackageManagerCore::setAutoConfirmCommand()
+{
+ d->m_autoConfirmCommand = true;
+}
+
+/*!
Returns the size of the component \a component as \a value.
*/
quint64 PackageManagerCore::size(QInstaller::Component *component, const QString &value) const
@@ -2370,6 +2378,11 @@ bool PackageManagerCore::removeInstallationSilently()
if (d->runningProcessesFound())
throw Error(tr("Running processes found."));
+ qCDebug(QInstaller::lcInstallerUninstallLog) << "Complete uninstallation was chosen.";
+ if (!(d->m_autoConfirmCommand || d->askUserConfirmCommand())) {
+ qCDebug(QInstaller::lcInstallerUninstallLog) << "Uninstallation aborted.";
+ return false;
+ }
setCompleteUninstallation(true);
return run();
}
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 5b8f8cc1a..fe044fa27 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -194,6 +194,8 @@ public:
Q_INVOKABLE bool containsFileDialogAutomaticAnswer(const QString &identifier) const;
QHash<QString, QString> fileDialogAutomaticAnswers() const;
+ void setAutoConfirmCommand();
+
quint64 size(QInstaller::Component *component, const QString &value) const;
Q_INVOKABLE bool isFileExtensionRegistered(const QString &extension) const;
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 89be5d907..6b5c4683f 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -222,6 +222,7 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core)
, m_checkAvailableSpace(true)
, m_autoAcceptLicenses(false)
, m_disableWriteMaintenanceTool(false)
+ , m_autoConfirmCommand(false)
{
}
@@ -259,6 +260,7 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, q
, m_checkAvailableSpace(true)
, m_autoAcceptLicenses(false)
, m_disableWriteMaintenanceTool(false)
+ , m_autoConfirmCommand(false)
{
foreach (const OperationBlob &operation, performedOperations) {
QScopedPointer<QInstaller::Operation> op(KDUpdater::UpdateOperationFactory::instance()
@@ -2548,7 +2550,9 @@ bool PackageManagerCorePrivate::calculateComponentsAndRun()
qCDebug(QInstaller::lcInstallerInstallLog) << "Installation canceled.";
} else if (componentsOk && acceptLicenseAgreements()) {
qCDebug(QInstaller::lcInstallerInstallLog).noquote() << htmlToString(htmlOutput);
- if (m_core->run()) {
+ if (!(m_autoConfirmCommand || askUserConfirmCommand())) {
+ qCDebug(QInstaller::lcInstallerInstallLog) << "Installation aborted.";
+ } else if (m_core->run()) {
// Write maintenance tool if required
m_core->writeMaintenanceTool();
return true;
@@ -2592,11 +2596,7 @@ bool PackageManagerCorePrivate::askUserAcceptLicense(const QString &name, const
"before continuing with the installation:" << name;
forever {
- qCDebug(QInstaller::lcInstallerInstallLog) << "Accept|Reject|Show";
-
- QTextStream stream(stdin);
- QString input;
- stream.readLineInto(&input);
+ const QString input = m_core->readConsoleLine(QLatin1String("Accept|Reject|Show"));
if (QString::compare(input, QLatin1String("Accept"), Qt::CaseInsensitive) == 0
|| QString::compare(input, QLatin1String("A"), Qt::CaseInsensitive) == 0) {
@@ -2658,4 +2658,23 @@ void PackageManagerCorePrivate::printLocalPackageInformation(const KDUpdater::Lo
qCDebug(QInstaller::lcPackageUpdateDate).noquote() << "\tLast updated:" << package.lastUpdateDate;
}
+bool PackageManagerCorePrivate::askUserConfirmCommand() const
+{
+ qCDebug(QInstaller::lcInstallerInstallLog) << "Do you want to continue?";
+
+ forever {
+ const QString input = m_core->readConsoleLine(QLatin1String("Yes|No"));
+
+ if (QString::compare(input, QLatin1String("Yes"), Qt::CaseInsensitive) == 0
+ || QString::compare(input, QLatin1String("Y"), Qt::CaseInsensitive) == 0) {
+ return true;
+ } else if (QString::compare(input, QLatin1String("No"), Qt::CaseInsensitive) == 0
+ || QString::compare(input, QLatin1String("N"), Qt::CaseInsensitive) == 0) {
+ return false;
+ } else {
+ qCDebug(QInstaller::lcInstallerInstallLog) << "Unknown answer:" << input;
+ }
+ }
+}
+
} // namespace QInstaller
diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h
index f78b52083..df7a887f2 100644
--- a/src/libs/installer/packagemanagercore_p.h
+++ b/src/libs/installer/packagemanagercore_p.h
@@ -210,6 +210,7 @@ public:
QStringList m_allowedRunningProcesses;
bool m_autoAcceptLicenses;
bool m_disableWriteMaintenanceTool;
+ bool m_autoConfirmCommand;
private slots:
void infoMessage(Job *, const QString &message) {
@@ -249,6 +250,7 @@ private:
bool calculateComponentsAndRun();
bool acceptLicenseAgreements() const;
bool askUserAcceptLicense(const QString &name, const QString &content) const;
+ bool askUserConfirmCommand() const;
void printPackageInformation(const QString &name, const Package *update);
void printLocalPackageInformation(const KDUpdater::LocalPackage package) const;
diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h
index 2ed99046c..845cad6ce 100644
--- a/src/sdk/sdkapp.h
+++ b/src/sdk/sdkapp.h
@@ -280,6 +280,9 @@ public:
if (m_parser.isSet(CommandLineOptions::scAcceptLicenses))
m_core->setAutoAcceptLicenses();
+ if (m_parser.isSet(CommandLineOptions::scConfirmCommand))
+ m_core->setAutoConfirmCommand();
+
// Ignore message acceptance options when running the installer with GUI
if (m_core->isCommandLineInstance()) {
if (m_parser.isSet(CommandLineOptions::scAcceptMessageQuery))
diff --git a/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp b/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp
index a8826124e..19fbee0a9 100644
--- a/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp
+++ b/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp
@@ -71,6 +71,7 @@ private slots:
QHash<QString, QString>(), true);
core->setAllowedRunningProcesses(QStringList() << QCoreApplication::applicationFilePath());
core->disableWriteMaintenanceTool();
+ core->setAutoConfirmCommand();
QSet<Repository> repoList;
Repository repo = Repository::fromUserInput(":///data/repository");
repoList.insert(repo);
diff --git a/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp b/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp
index 83d93d647..464e1eef7 100644
--- a/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp
+++ b/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp
@@ -97,6 +97,7 @@ private slots:
QHash<QString, QString>(), true);
core->setAllowedRunningProcesses(QStringList() << QCoreApplication::applicationFilePath());
core->disableWriteMaintenanceTool();
+ core->setAutoConfirmCommand();
m_installDir = QInstaller::generateTemporaryFileName();
QVERIFY(QDir().mkpath(m_installDir));
core->setValue(scTargetDir, m_installDir);
diff --git a/tests/auto/installer/shared/packagemanager.h b/tests/auto/installer/shared/packagemanager.h
index a62f13484..d5260ef5e 100644
--- a/tests/auto/installer/shared/packagemanager.h
+++ b/tests/auto/installer/shared/packagemanager.h
@@ -47,6 +47,7 @@ struct PackageManager
QString appFilePath = QCoreApplication::applicationFilePath();
core->setAllowedRunningProcesses(QStringList() << appFilePath);
core->disableWriteMaintenanceTool();
+ core->setAutoConfirmCommand();
QSet<Repository> repoList;
Repository repo = Repository::fromUserInput(repository);
repoList.insert(repo);