From da6c97cc99162aa1a4916e7b77eefd7f631d11af Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Thu, 20 Oct 2022 14:58:28 +0300 Subject: CLI: Add new '--cache-path' option The option can be used to select the path for metadata cache without opening the installer's settings dialog. Add public PackageManagerCore::resetLocalCache() function and remove automatic initialization of the local cache in the private core class constructor, so we can control the timeline better. Also make PackageManagerCore::clearLocalCache() a regular member function as it does not need to be a Qt slot. Task-number: QTIFW-2810 Change-Id: Ia4a903026a10b90da16ba1b93fd3098a709f7ed7 Reviewed-by: Katja Marttila --- src/libs/installer/commandlineparser.cpp | 4 ++++ src/libs/installer/constants.h | 2 ++ src/libs/installer/packagemanagercore.cpp | 14 ++++++++++++-- src/libs/installer/packagemanagercore.h | 4 +++- src/libs/installer/packagemanagercore_p.cpp | 1 - src/sdk/sdkapp.h | 10 ++++++++++ 6 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/libs/installer/commandlineparser.cpp b/src/libs/installer/commandlineparser.cpp index fd870da2d..3b5b46e0e 100644 --- a/src/libs/installer/commandlineparser.cpp +++ b/src/libs/installer/commandlineparser.cpp @@ -173,6 +173,10 @@ CommandLineParser::CommandLineParser() "search command. The keys can be any of the possible package information elements, like " "\"DisplayName\" and \"Description\"."), QLatin1String("element=regex,...")), CommandLineOnly); + addOption(QCommandLineOption(QStringList() + << CommandLineOptions::scLocalCachePathShort << CommandLineOptions::scLocalCachePathLong, + QLatin1String("Sets the path used for local metadata cache. The path must be writable by the current user."), + QLatin1String("path"))); // Message query options addOptionWithContext(QCommandLineOption(QStringList() << CommandLineOptions::scAcceptMessageQueryShort diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h index 77fc0237f..485982672 100644 --- a/src/libs/installer/constants.h +++ b/src/libs/installer/constants.h @@ -213,6 +213,8 @@ static const QLatin1String scNoDefaultInstallationShort("nd"); static const QLatin1String scNoDefaultInstallationLong("no-default-installations"); static const QLatin1String scFilterPackagesShort("fp"); static const QLatin1String scFilterPackagesLong("filter-packages"); +static const QLatin1String scLocalCachePathShort("cp"); +static const QLatin1String scLocalCachePathLong("cache-path"); // Developer options static const QLatin1String scScriptShort("s"); diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 48d071321..d5f830903 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -573,12 +573,22 @@ void PackageManagerCore::cancelMetaInfoJob() d->m_metadataJob.cancel(); } +/*! + Resets the cache used to store downloaded metadata, if one was previously + initialized. If \a init is set to \c true, the cache is reinitialized for + the path configured in installer's settings. + + Returns \c true on success, \c false otherwise. +*/ +bool PackageManagerCore::resetLocalCache(bool init) +{ + return d->m_metadataJob.resetCache(init); +} + /*! Clears the contents of the cache used to store downloaded metadata. Returns \c true on success, \c false otherwise. An error string can be retrieved with \a error. - - \sa {installer::clearLocalCache}{installer.clearLocalCache} */ bool PackageManagerCore::clearLocalCache(QString *error) { diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h index db1c0765f..2c307971a 100644 --- a/src/libs/installer/packagemanagercore.h +++ b/src/libs/installer/packagemanagercore.h @@ -345,6 +345,9 @@ public: void createLocalDependencyHash(const QString &component, const QString &dependencies) const; void createAutoDependencyHash(const QString &component, const QString &oldDependencies, const QString &newDependencies) const; + bool resetLocalCache(bool init = false); + bool clearLocalCache(QString *error = nullptr); + public Q_SLOTS: bool runInstaller(); bool runUninstaller(); @@ -355,7 +358,6 @@ public Q_SLOTS: void languageChanged(); void setCompleteUninstallation(bool complete); void cancelMetaInfoJob(); - bool clearLocalCache(QString *error = nullptr); void componentsToInstallNeedsRecalculation(); void calculateUserSelectedComponentsToInstall(const QList &indexes); void clearComponentsToInstallCalculated(); diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index c61c6bc99..64af77a98 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -664,7 +664,6 @@ void PackageManagerCorePrivate::initialize(const QHash ¶ms m_metadataJob.disconnect(); m_metadataJob.setAutoDelete(false); m_metadataJob.setPackageManagerCore(m_core); - m_metadataJob.resetCache(true); connect(&m_metadataJob, &Job::infoMessage, this, &PackageManagerCorePrivate::infoMessage); connect(&m_metadataJob, &Job::progress, this, &PackageManagerCorePrivate::infoProgress); diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h index d5d126f26..7d39ee3cf 100644 --- a/src/sdk/sdkapp.h +++ b/src/sdk/sdkapp.h @@ -266,6 +266,16 @@ public: KDUpdater::FileDownloaderFactory::instance().setProxyFactory(m_core->proxyFactory()); } + if (m_parser.isSet(CommandLineOptions::scLocalCachePathLong)) { + const QString cachePath = m_parser.value(CommandLineOptions::scLocalCachePathLong); + if (cachePath.isEmpty()) { + errorMessage = QObject::tr("Empty value for option 'cache-path'."); + return false; + } + m_core->settings().setLocalCachePath(cachePath); + } + m_core->resetLocalCache(true); + if (m_parser.isSet(CommandLineOptions::scShowVirtualComponentsLong)) QInstaller::PackageManagerCore::setVirtualComponentsVisible(true); -- cgit v1.2.3