summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/packagemanagercore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer/packagemanagercore.cpp')
-rw-r--r--src/libs/installer/packagemanagercore.cpp135
1 files changed, 92 insertions, 43 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 81fd29472..2b7ec4536 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -60,12 +60,14 @@
#include <QtCore/QMutex>
#include <QtCore/QSettings>
#include <QtCore/QTemporaryFile>
+#include <QtCore/QTextCodec>
+#include <QtCore/QTextStream>
#include <QDesktopServices>
#include <QFileDialog>
-#include "kdsysinfo.h"
-#include "kdupdaterupdateoperationfactory.h"
+#include "sysinfo.h"
+#include "updateoperationfactory.h"
#ifdef Q_OS_WIN
# include "qt_windows.h"
@@ -427,7 +429,7 @@ void PackageManagerCore::writeMaintenanceTool()
gainAdminRights();
gainedAdminRights = true;
}
- d->m_updaterApplication.packagesInfo()->writeToDisk();
+ d->m_localPackageHub->writeToDisk();
if (gainedAdminRights)
dropAdminRights();
d->m_needToWriteMaintenanceTool = false;
@@ -638,11 +640,11 @@ int PackageManagerCore::downloadNeededArchives(double partProgressSize)
DownloadArchivesJob archivesJob(this);
archivesJob.setAutoDelete(false);
archivesJob.setArchivesToDownload(archivesToDownload);
- connect(this, SIGNAL(installationInterrupted()), &archivesJob, SLOT(cancel()));
- connect(&archivesJob, SIGNAL(outputTextChanged(QString)), ProgressCoordinator::instance(),
- SLOT(emitLabelAndDetailTextChanged(QString)));
- connect(&archivesJob, SIGNAL(downloadStatusChanged(QString)), ProgressCoordinator::instance(),
- SIGNAL(downloadStatusChanged(QString)));
+ connect(this, &PackageManagerCore::installationInterrupted, &archivesJob, &Job::cancel);
+ connect(&archivesJob, &DownloadArchivesJob::outputTextChanged,
+ ProgressCoordinator::instance(), &ProgressCoordinator::emitLabelAndDetailTextChanged);
+ connect(&archivesJob, &DownloadArchivesJob::downloadStatusChanged,
+ ProgressCoordinator::instance(), &ProgressCoordinator::downloadStatusChanged);
ProgressCoordinator::instance()->registerPartProgress(&archivesJob,
SIGNAL(progressChanged(double)), partProgressSize);
@@ -650,13 +652,13 @@ int PackageManagerCore::downloadNeededArchives(double partProgressSize)
archivesJob.start();
archivesJob.waitForFinished();
- if (archivesJob.error() == KDJob::Canceled)
+ if (archivesJob.error() == Job::Canceled)
interrupt();
- else if (archivesJob.error() != KDJob::NoError)
+ else if (archivesJob.error() != Job::NoError)
throw Error(archivesJob.errorString());
if (d->statusCanceledOrFailed())
- throw Error(tr("Installation canceled by user"));
+ throw Error(tr("Installation canceled by user."));
ProgressCoordinator::instance()->emitDownloadStatus(tr("All downloads finished."));
@@ -705,7 +707,6 @@ void PackageManagerCore::rollBackInstallation()
}
}
- KDUpdater::PackagesInfo &packages = *d->m_updaterApplication.packagesInfo();
while (!d->m_performedOperationsCurrentSession.isEmpty()) {
try {
Operation *const operation = d->m_performedOperationsCurrentSession.takeLast();
@@ -732,14 +733,14 @@ void PackageManagerCore::rollBackInstallation()
component = d->componentsToReplace().value(componentName).second;
if (component) {
component->setUninstalled();
- packages.removePackage(component->name());
+ d->m_localPackageHub->removePackage(component->name());
}
}
- packages.writeToDisk();
+ d->m_localPackageHub->writeToDisk();
if (isInstaller()) {
- if (packages.packageInfoCount() == 0) {
- QFile file(packages.fileName());
+ if (d->m_localPackageHub->packageInfoCount() == 0) {
+ QFile file(d->m_localPackageHub->fileName());
file.remove();
}
}
@@ -749,7 +750,7 @@ void PackageManagerCore::rollBackInstallation()
} catch (const Error &e) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("ElevationError"), tr("Authentication Error"), tr("Some components "
- "could not be removed completely because admin rights could not be acquired: %1.")
+ "could not be removed completely because administrative rights could not be acquired: %1.")
.arg(e.message()));
} catch (...) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), QLatin1String("unknown"),
@@ -785,6 +786,32 @@ bool PackageManagerCore::fileExists(const QString &filePath) const
return QFileInfo(filePath).exists();
}
+/*!
+ Returns the contents of the file \a filePath using the encoding specified
+ by \a codecName. The file is read in the text mode, that is, end-of-line
+ terminators are translated to the local encoding.
+
+ \note If the file does not exist or an error occurs while reading the file, an
+ empty string is returned.
+
+ \sa {installer::readFile}{installer.readFile}
+
+ */
+QString PackageManagerCore::readFile(const QString &filePath, const QString &codecName) const
+{
+ QFile f(filePath);
+ if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
+ return QString();
+
+ QTextCodec *codec = QTextCodec::codecForName(qPrintable(codecName));
+ if (!codec)
+ return QString();
+
+ QTextStream stream(&f);
+ stream.setCodec(codec);
+ return stream.readAll();
+}
+
// -- QInstaller
/*!
@@ -867,7 +894,7 @@ PackageManagerCore::~PackageManagerCore()
delete d;
RemoteClient::instance().setActive(false);
- RemoteClient::instance().shutdown();
+ RemoteClient::instance().destroy();
QMutexLocker _(globalVirtualComponentsFontMutex());
delete sVirtualComponentsFont;
@@ -966,7 +993,7 @@ bool PackageManagerCore::fetchLocalPackagesTree()
d->setStatus(Running);
if (!isPackageManager()) {
- d->setStatus(Failure, tr("Application not running in Package Manager mode!"));
+ d->setStatus(Failure, tr("Application not running in Package Manager mode."));
return false;
}
@@ -988,7 +1015,7 @@ bool PackageManagerCore::fetchLocalPackagesTree()
component->loadDataFromPackage(installedPackages.value(key));
const QString &name = component->name();
if (components.contains(name)) {
- qCritical("Could not register component! Component with identifier %s already registered.",
+ qCritical("Cannot register component! Component with identifier %s already registered.",
qPrintable(name));
continue;
}
@@ -1025,8 +1052,18 @@ void PackageManagerCore::networkSettingsChanged()
d->m_repoFetched = false;
d->m_updateSourcesAdded = false;
- if (d->isUpdater() || d->isPackageManager())
+ if (isMaintainer() ) {
+ bool gainedAdminRights = false;
+ QTemporaryFile tempAdminFile(d->targetDir() + QStringLiteral("/XXXXXX"));
+ if (!tempAdminFile.open() || !tempAdminFile.isWritable()) {
+ gainAdminRights();
+ gainedAdminRights = true;
+ }
d->writeMaintenanceConfigFiles();
+ if (gainedAdminRights)
+ dropAdminRights();
+ }
+
KDUpdater::FileDownloaderFactory::instance().setProxyFactory(proxyFactory());
emit coreNetworkSettingsChanged();
@@ -1074,7 +1111,7 @@ bool PackageManagerCore::fetchRemotePackagesTree()
d->setStatus(Running);
if (isUninstaller()) {
- d->setStatus(Failure, tr("Application running in Uninstaller mode!"));
+ d->setStatus(Failure, tr("Application running in Uninstaller mode."));
return false;
}
@@ -1110,7 +1147,7 @@ bool PackageManagerCore::fetchRemotePackagesTree()
}
const LocalPackage localPackage = installedPackages.value(name);
- const QString updateVersion = update->data(scRemoteVersion).toString();
+ const QString updateVersion = update->data(scVersion).toString();
if (KDUpdater::compareVersion(updateVersion, localPackage.version) <= 0)
break; // remote version equals or is less than the installed maintenance tool
@@ -1617,8 +1654,8 @@ ComponentModel *PackageManagerCore::defaultComponentModel() const
d->m_defaultModel = componentModel(const_cast<PackageManagerCore*> (this),
QLatin1String("AllComponentsModel"));
}
- connect(this, SIGNAL(finishAllComponentsReset(QList<QInstaller::Component*>)), d->m_defaultModel,
- SLOT(setRootComponents(QList<QInstaller::Component*>)));
+ connect(this, &PackageManagerCore::finishAllComponentsReset, d->m_defaultModel,
+ &ComponentModel::setRootComponents);
return d->m_defaultModel;
}
@@ -1632,8 +1669,8 @@ ComponentModel *PackageManagerCore::updaterComponentModel() const
d->m_updaterModel = componentModel(const_cast<PackageManagerCore*> (this),
QLatin1String("UpdaterComponentsModel"));
}
- connect(this, SIGNAL(finishUpdaterComponentsReset(QList<QInstaller::Component*>)), d->m_updaterModel,
- SLOT(setRootComponents(QList<QInstaller::Component*>)));
+ connect(this, &PackageManagerCore::finishUpdaterComponentsReset, d->m_updaterModel,
+ &ComponentModel::setRootComponents);
return d->m_updaterModel;
}
@@ -1701,20 +1738,21 @@ bool PackageManagerCore::killProcess(const QString &absoluteFilePath) const
processPath = QDir::cleanPath(processPath.replace(QLatin1Char('\\'), QLatin1Char('/')));
if (processPath == normalizedPath) {
- qDebug() << QString::fromLatin1("try to kill process: %1(%2)").arg(process.name).arg(process.id);
+ qDebug().nospace() << "try to kill process " << process.name << " (" << process.id << ")";
//to keep the ui responsible use QtConcurrent::run
QFutureWatcher<bool> futureWatcher;
const QFuture<bool> future = QtConcurrent::run(KDUpdater::killProcess, process, 30000);
QEventLoop loop;
- loop.connect(&futureWatcher, SIGNAL(finished()), SLOT(quit()), Qt::QueuedConnection);
+ connect(&futureWatcher, &QFutureWatcher<bool>::finished,
+ &loop, &QEventLoop::quit, Qt::QueuedConnection);
futureWatcher.setFuture(future);
if (!future.isFinished())
loop.exec();
- qDebug() << QString::fromLatin1("\"%1\" killed!").arg(process.name);
+ qDebug() << process.name << "killed!";
return future.result();
}
}
@@ -1865,14 +1903,7 @@ QString PackageManagerCore::environmentVariable(const QString &name) const
*/
bool PackageManagerCore::operationExists(const QString &name)
{
- static QSet<QString> existingOperations;
- if (existingOperations.contains(name))
- return true;
- QScopedPointer<Operation> op(KDUpdater::UpdateOperationFactory::instance().create(name));
- if (!op.data())
- return false;
- existingOperations.insert(name);
- return true;
+ return KDUpdater::UpdateOperationFactory::instance().containsProduct(name);
}
/*!
@@ -1884,7 +1915,7 @@ bool PackageManagerCore::operationExists(const QString &name)
*/
bool PackageManagerCore::performOperation(const QString &name, const QStringList &arguments)
{
- QScopedPointer<Operation> op(KDUpdater::UpdateOperationFactory::instance().create(name));
+ QScopedPointer<Operation> op(KDUpdater::UpdateOperationFactory::instance().create(name, this));
if (!op.data())
return false;
@@ -2261,6 +2292,14 @@ bool PackageManagerCore::isPackageManager() const
}
/*!
+ Returns \c true if it is a package manager or an updater.
+*/
+bool PackageManagerCore::isMaintainer() const
+{
+ return isPackageManager() || isUpdater();
+}
+
+/*!
Runs the installer. Returns \c true on success, \c false otherwise.
\sa {installer::runInstaller}{installer.runInstaller}
@@ -2309,7 +2348,7 @@ bool PackageManagerCore::run()
return d->runInstaller();
else if (isUninstaller())
return d->runUninstaller();
- else if (isPackageManager() || isUpdater())
+ else if (isMaintainer())
return d->runPackageUpdater();
return false;
}
@@ -2328,7 +2367,7 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo
// check if we already added the component to the available components list
const QString name = data.package->data(scName).toString();
if (data.components->contains(name)) {
- qCritical("Could not register component! Component with identifier %s already registered.",
+ qCritical("Cannot register component! Component with identifier %s already registered.",
qPrintable(name));
return false;
}
@@ -2529,7 +2568,7 @@ bool PackageManagerCore::fetchUpdaterPackages(const PackagesList &remotes, const
continue; // Update for not installed package found, skip it.
const LocalPackage &localPackage = locals.value(name);
- const QString updateVersion = update->data(scRemoteVersion).toString();
+ const QString updateVersion = update->data(scVersion).toString();
if (KDUpdater::compareVersion(updateVersion, localPackage.version) <= 0)
continue;
@@ -2650,7 +2689,7 @@ void PackageManagerCore::updateDisplayVersions(const QString &displayKey)
}
visited.clear();
const QString displayVersionRemote = findDisplayVersion(key, componentsHash,
- scRemoteVersion, visited);
+ scVersion, visited);
if (displayVersionRemote.isEmpty())
componentsHash.value(key)->setValue(displayKey, tr("invalid"));
else
@@ -2698,3 +2737,13 @@ ComponentModel *PackageManagerCore::componentModel(PackageManagerCore *core, con
return model;
}
+
+QStringList PackageManagerCore::filesForDelayedDeletion() const
+{
+ return d->m_filesForDelayedDeletion;
+}
+
+void PackageManagerCore::addFilesForDelayedDeletion(const QStringList &files)
+{
+ d->m_filesForDelayedDeletion.append(files);
+}