diff options
author | Katja Marttila <katja.marttila@qt.io> | 2020-12-22 09:53:36 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2020-12-30 11:10:05 +0200 |
commit | 7be83635627ca1384862a8826de2d85979cdfc8e (patch) | |
tree | 5d25666643ae7de865f73b93ffa80bf3c97d594f | |
parent | a606c9915b8ff1d6001a83aa350400d6286706ff (diff) |
Allow disabling undo of GlobalSettings during uninstall
Task-number: QTIFW-1973
Change-Id: I89f15c8ed7d56c3e1bc72d3c740e9054363f9390
Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
-rw-r--r-- | doc/operations.qdoc | 4 | ||||
-rw-r--r-- | src/libs/installer/globalsettingsoperation.cpp | 9 | ||||
-rw-r--r-- | src/libs/kdtools/updateoperation.cpp | 34 | ||||
-rw-r--r-- | src/libs/kdtools/updateoperation.h | 2 | ||||
-rw-r--r-- | tests/auto/installer/globalsettingsoperation/globalsettingsoperation.pro | 10 | ||||
-rw-r--r-- | tests/auto/installer/globalsettingsoperation/tst_globalsettingsoperation.cpp | 95 | ||||
-rw-r--r-- | tests/auto/installer/installer.pro | 3 |
7 files changed, 153 insertions, 4 deletions
diff --git a/doc/operations.qdoc b/doc/operations.qdoc index 983985dc7..4186f8e99 100644 --- a/doc/operations.qdoc +++ b/doc/operations.qdoc @@ -195,6 +195,10 @@ registry) or by \c application and \c company name. Set \c scope to "SystemScope" to create an entry in the system scope. + \note GlobalConfig will be reset during uninstallation. If you want to make the + config persistent, you can overwrite the \e UNDO by passing \e UNDOOPERATION and + \e "", to the end of the argument list. + \note The operation is using QSettings to store the key value pair. QSettings always treats backslash as a special character and provides no API for reading or writing such entries. Do not use slashes ('/' and '\\') in section or key names; diff --git a/src/libs/installer/globalsettingsoperation.cpp b/src/libs/installer/globalsettingsoperation.cpp index f1f184ceb..dc085f4b6 100644 --- a/src/libs/installer/globalsettingsoperation.cpp +++ b/src/libs/installer/globalsettingsoperation.cpp @@ -49,8 +49,9 @@ void GlobalSettingsOperation::backup() bool GlobalSettingsOperation::performOperation() { + const QStringList args = parsePerformOperationArguments(); QString key, value; - QScopedPointer<QSettingsWrapper> settings(setup(&key, &value, arguments())); + QScopedPointer<QSettingsWrapper> settings(setup(&key, &value, args)); if (settings.isNull()) return false; @@ -76,8 +77,12 @@ bool GlobalSettingsOperation::performOperation() bool GlobalSettingsOperation::undoOperation() { + if (parseUndoOperationArguments().count() > 0) + return true; + + const QStringList args = parsePerformOperationArguments(); QString key, val; - QScopedPointer<QSettingsWrapper> settings(setup(&key, &val, arguments())); + QScopedPointer<QSettingsWrapper> settings(setup(&key, &val, args)); if (settings.isNull()) return false; diff --git a/src/libs/kdtools/updateoperation.cpp b/src/libs/kdtools/updateoperation.cpp index b884fa9fa..267cd8a80 100644 --- a/src/libs/kdtools/updateoperation.cpp +++ b/src/libs/kdtools/updateoperation.cpp @@ -190,7 +190,7 @@ QStringList UpdateOperation::arguments() const bool UpdateOperation::checkArgumentCount(int minArgCount, int maxArgCount, const QString &argDescription) { - const int argCount = arguments().count(); + const int argCount = parsePerformOperationArguments().count(); if (argCount < minArgCount || argCount > maxArgCount) { setError(InvalidArguments); QString countRange; @@ -226,6 +226,38 @@ bool UpdateOperation::checkArgumentCount(int argCount) return checkArgumentCount(argCount, argCount); } +/*! + Returns operation argument list without + \c UNDOOOPERATION arguments. +*/ +QStringList UpdateOperation::parsePerformOperationArguments() +{ + QStringList args; + int index = arguments().indexOf(QLatin1String("UNDOOPERATION")); + args = arguments().mid(0, index); + return args; +} + +/*! + Returns undo operation argument list. If the installation is + cancelled or failed, returns an empty list so that full undo + operation can be performed. +*/ +QStringList UpdateOperation::parseUndoOperationArguments() +{ + //Install has failed, allow a normal undo + if (m_core && (m_core->status() == QInstaller::PackageManagerCore::Canceled + || m_core->status() == QInstaller::PackageManagerCore::Failure)) { + return QStringList(); + } + int index = arguments().indexOf(QLatin1String("UNDOOPERATION")); + QStringList args; + if ((index != -1) && (arguments().length() > index + 1)) { + args = arguments().mid(index + 1); + } + return args; +} + struct StartsWith { StartsWith(const QString &searchTerm) diff --git a/src/libs/kdtools/updateoperation.h b/src/libs/kdtools/updateoperation.h index 45120ab95..b3642c78e 100644 --- a/src/libs/kdtools/updateoperation.h +++ b/src/libs/kdtools/updateoperation.h @@ -91,6 +91,8 @@ protected: bool deleteFileNowOrLater(const QString &file, QString *errorString = 0); bool checkArgumentCount(int minArgCount, int maxArgCount, const QString &argDescription = QString()); bool checkArgumentCount(int argCount); + QStringList parsePerformOperationArguments(); + QStringList parseUndoOperationArguments(); private: QString m_name; diff --git a/tests/auto/installer/globalsettingsoperation/globalsettingsoperation.pro b/tests/auto/installer/globalsettingsoperation/globalsettingsoperation.pro new file mode 100644 index 000000000..ddae3b1d7 --- /dev/null +++ b/tests/auto/installer/globalsettingsoperation/globalsettingsoperation.pro @@ -0,0 +1,10 @@ +include(../../qttest.pri) + +QT -= gui +QT += testlib + +SOURCES = tst_globalsettingsoperation.cpp + +RESOURCES += \ + ..\shared\config.qrc + diff --git a/tests/auto/installer/globalsettingsoperation/tst_globalsettingsoperation.cpp b/tests/auto/installer/globalsettingsoperation/tst_globalsettingsoperation.cpp new file mode 100644 index 000000000..009673f24 --- /dev/null +++ b/tests/auto/installer/globalsettingsoperation/tst_globalsettingsoperation.cpp @@ -0,0 +1,95 @@ +/************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "../shared/packagemanager.h" + +#include <globalsettingsoperation.h> +#include <environment.h> +#include <packagemanagercore.h> + +#include <QSettings> +#include <QTest> + +using namespace QInstaller; +using namespace KDUpdater; + +class tst_globalsettingsoperation : public QObject +{ + Q_OBJECT + +private: + void cleanSettings() + { + QSettings testSettings("QtProject", "QtProject.QtIfwTest"); + testSettings.setValue("QtIfwTestKey", ""); + } + + +private slots: + void initTestCase() + { + cleanSettings(); + } + + void cleanupTestCase() + { + cleanSettings(); + } + + void setGlobalSettingsValue() + { + GlobalSettingsOperation settingsOperation(nullptr); + settingsOperation.setArguments(QStringList() << "QtProject" << "QtProject.QtIfwTest" << "QtIfwTestKey" << "QtIfwTestValue"); + settingsOperation.backup(); + QVERIFY2(settingsOperation.performOperation(), settingsOperation.errorString().toLatin1()); + + QSettings testSettings("QtProject", "QtProject.QtIfwTest"); + QCOMPARE("QtIfwTestValue", testSettings.value("QtIfwTestKey")); + QVERIFY2(settingsOperation.undoOperation(), settingsOperation.errorString().toLatin1()); + QCOMPARE("", testSettings.value("QtIfwTestKey")); + } + + void setGlobalSettingsValueNoUndo() + { + + GlobalSettingsOperation settingsOperation(nullptr); + settingsOperation.setArguments(QStringList() << "QtProject" << "QtProject.QtIfwTest" << "QtIfwTestKey" << "QtIfwTestValue" << "UNDOOPERATION" << ""); + settingsOperation.backup(); + QVERIFY2(settingsOperation.performOperation(), settingsOperation.errorString().toLatin1()); + + QSettings testSettings("QtProject", "QtProject.QtIfwTest"); + QCOMPARE("QtIfwTestValue", testSettings.value("QtIfwTestKey")); + QVERIFY2(settingsOperation.undoOperation(), settingsOperation.errorString().toLatin1()); + QCOMPARE("QtIfwTestValue", testSettings.value("QtIfwTestKey")); + } +}; + +QTEST_MAIN(tst_globalsettingsoperation) + +#include "tst_globalsettingsoperation.moc" + diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro index 81def2f76..2c55de40c 100644 --- a/tests/auto/installer/installer.pro +++ b/tests/auto/installer/installer.pro @@ -35,7 +35,8 @@ SUBDIRS += \ commandlineupdate \ moveoperation \ environmentvariableoperation \ - licenseagreement + licenseagreement \ + globalsettingsoperation win32 { SUBDIRS += registerfiletypeoperation \ |