summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/testapp/mainwindow.cpp2
-rw-r--r--examples/testapp/updateagent.cpp2
-rw-r--r--installerbuilder/installerbase/tabcontroller.cpp4
-rw-r--r--installerbuilder/libinstaller/packagemanagercore.cpp439
-rw-r--r--installerbuilder/libinstaller/packagemanagercore.h16
-rw-r--r--installerbuilder/libinstaller/packagemanagercore_p.cpp109
-rw-r--r--installerbuilder/libinstaller/packagemanagercore_p.h14
-rw-r--r--installerbuilder/libinstaller/updater.cpp2
8 files changed, 299 insertions, 289 deletions
diff --git a/examples/testapp/mainwindow.cpp b/examples/testapp/mainwindow.cpp
index 9a8f7e96e..91a13780a 100644
--- a/examples/testapp/mainwindow.cpp
+++ b/examples/testapp/mainwindow.cpp
@@ -92,7 +92,7 @@ void MainWindow::checkForUpdates()
m_core.setTemporaryRepositories(settings.repositories());
settings.setLastCheck(QDateTime::currentDateTime());
- if (!m_core.fetchUpdaterPackages()) {
+ if (!m_core.fetchRemotePackagesTree()) {
settings.setLastResult(tr("Software Update failed."));
QMessageBox::information(this, tr("Check for Updates"), tr("Failed to retrieve updates!"));
return;
diff --git a/examples/testapp/updateagent.cpp b/examples/testapp/updateagent.cpp
index 73db16e98..994440a48 100644
--- a/examples/testapp/updateagent.cpp
+++ b/examples/testapp/updateagent.cpp
@@ -78,7 +78,7 @@ public:
PackageManagerCore core(QInstaller::MagicUpdaterMarker);
core.setTemporaryRepositories(settings.repositories());
- if (!core.fetchUpdaterPackages())
+ if (!core.fetchRemotePackagesTree())
throw Error(tr("Software Update failed."));
settings.setLastResult(tr("Software Update run successfully."));
diff --git a/installerbuilder/installerbase/tabcontroller.cpp b/installerbuilder/installerbase/tabcontroller.cpp
index 67c4a8d51..6dd0c21ed 100644
--- a/installerbuilder/installerbase/tabcontroller.cpp
+++ b/installerbuilder/installerbase/tabcontroller.cpp
@@ -170,7 +170,7 @@ int TabController::initUpdater()
d->m_gui->show();
if (!d->m_updatesFetched) {
- d->m_updatesFetched = d->m_core->fetchUpdaterPackages();
+ d->m_updatesFetched = d->m_core->fetchRemotePackagesTree();
if (!d->m_updatesFetched)
introPage->setErrorMessage(d->m_core->error());
}
@@ -235,7 +235,7 @@ int TabController::initPackageManager()
bool localPackagesTreeFetched = false;
if (!d->m_allPackagesFetched) {
// first try to fetch the server side packages tree
- d->m_allPackagesFetched = d->m_core->fetchAllPackages();
+ d->m_allPackagesFetched = d->m_core->fetchRemotePackagesTree();
if (!d->m_allPackagesFetched) {
const QString error = d->m_core->error();
// if that fails, try to fetch local installed tree
diff --git a/installerbuilder/libinstaller/packagemanagercore.cpp b/installerbuilder/libinstaller/packagemanagercore.cpp
index 6f57aaa79..09ea46194 100644
--- a/installerbuilder/libinstaller/packagemanagercore.cpp
+++ b/installerbuilder/libinstaller/packagemanagercore.cpp
@@ -57,7 +57,6 @@
#include <KDToolsCore/KDSysInfo>
#include <KDUpdater/Update>
-#include <KDUpdater/UpdateFinder>
#include <KDUpdater/UpdateOperation>
#include <KDUpdater/UpdateOperationFactory>
@@ -535,7 +534,7 @@ void PackageManagerCore::rollBackInstallation()
if (!componentName.isEmpty()) {
Component *component = componentByName(componentName);
if (!component)
- component = d->componentsToReplace().value(componentName).second;
+ component = d->componentsToReplace(runMode()).value(componentName).second;
if (component) {
component->setUninstalled();
packages.removePackage(component->name());
@@ -640,34 +639,19 @@ RunMode PackageManagerCore::runMode() const
return isUpdater() ? UpdaterMode : AllMode;
}
-bool PackageManagerCore::fetchAllPackages()
+bool PackageManagerCore::fetchLocalPackagesTree()
{
d->setStatus(Running);
- if (isUninstaller() || isUpdater()) {
- d->setStatus(Failure, tr("Application not running in Installer or Package Manager mode!"));
+ if (!isPackageManager()) {
+ d->setStatus(Failure, tr("Application not running in Package Manager mode!"));
return false;
}
- QHash<QString, KDUpdater::PackageInfo> installedPackages = d->localInstalledPackages();
- if (isPackageManager() && status() == Failure)
- return false;
-
- if (!d->fetchMetaInformationFromRepositories())
- return false;
-
- if (!d->addUpdateResourcesFromRepositories(true))
- return false;
-
- KDUpdater::UpdateFinder updateFinder(&d->m_updaterApplication);
- updateFinder.setAutoDelete(false);
- updateFinder.setUpdateType(KDUpdater::PackageUpdate | KDUpdater::NewPackage);
- updateFinder.run();
-
- const QList<KDUpdater::Update*> &packages = updateFinder.updates();
- if (packages.isEmpty()) {
- verbose() << tr("Could not retrieve components: %1.").arg(updateFinder.errorString());
- d->setStatus(Failure, tr("Could not retrieve components: %1.").arg(updateFinder.errorString()));
+ LocalPackages installedPackages = d->localInstalledPackages();
+ if (installedPackages.isEmpty()) {
+ if (status() != Failure)
+ d->setStatus(Failure, tr("No installed packages found."));
return false;
}
@@ -676,24 +660,19 @@ bool PackageManagerCore::fetchAllPackages()
d->clearAllComponentLists();
QMap<QString, QInstaller::Component*> components;
- Data data;
- data.components = &components;
- data.installedPackages = &installedPackages;
-
- foreach (KDUpdater::Update *package, packages) {
+ const QStringList &keys = installedPackages.keys();
+ foreach (const QString &key, keys) {
QScopedPointer<QInstaller::Component> component(new QInstaller::Component(this));
-
- data.package = package;
- component->loadDataFromUpdate(package);
- if (updateComponentData(data, component.data())) {
- const QString name = component->name();
- components.insert(name, component.take());
+ component->loadDataFromPackageInfo(installedPackages.value(key));
+ const QString &name = component->name();
+ if (components.contains(name)) {
+ qCritical("Could not register component! Component with identifier %s already registered.",
+ qPrintable(name));
+ continue;
}
+ components.insert(name, component.take());
}
- // store all components that got a replacement
- storeReplacedComponents(components, data.replacementToExchangeables);
-
// now append all components to their respective parents
QMap<QString, QInstaller::Component*>::const_iterator it;
for (it = components.begin(); it != components.end(); ++it) {
@@ -712,16 +691,6 @@ bool PackageManagerCore::fetchAllPackages()
appendRootComponent(component, AllMode);
}
- try {
- // after everything is set up, load the scripts
- foreach (QInstaller::Component *component, components)
- component->loadComponentScript();
- } catch (const Error &error) {
- d->clearAllComponentLists();
- emit finishAllComponentsReset();
- d->setStatus(Failure, error.message());
- return false;
- }
// now set the checked state for all components without child
for (int i = 0; i < rootComponentCount(AllMode); ++i) {
QList<Component*> children = rootComponent(i, AllMode)->childs();
@@ -733,23 +702,23 @@ bool PackageManagerCore::fetchAllPackages()
}
}
- d->setStatus(Success);
emit finishAllComponentsReset();
+ d->setStatus(Success);
return true;
}
-bool PackageManagerCore::fetchUpdaterPackages()
+bool PackageManagerCore::fetchRemotePackagesTree()
{
d->setStatus(Running);
- if (!isUpdater()) {
- d->setStatus(Failure, tr("Application not running in Updater mode!"));
+ if (isUninstaller()) {
+ d->setStatus(Failure, tr("Application running in Uninstaller mode!"));
return false;
}
- QHash<QString, KDUpdater::PackageInfo> installedPackages = d->localInstalledPackages();
- if (status() == Failure)
+ const LocalPackages installedPackages = d->localInstalledPackages();
+ if (!isInstaller() && status() == Failure)
return false;
if (!d->fetchMetaInformationFromRepositories())
@@ -758,184 +727,19 @@ bool PackageManagerCore::fetchUpdaterPackages()
if (!d->addUpdateResourcesFromRepositories(true))
return false;
- KDUpdater::UpdateFinder updateFinder(&d->m_updaterApplication);
- updateFinder.setAutoDelete(false);
- updateFinder.setUpdateType(KDUpdater::PackageUpdate | KDUpdater::NewPackage);
- updateFinder.run();
-
- const QList<KDUpdater::Update*> &updates = updateFinder.updates();
- if (updates.isEmpty()) {
- verbose() << tr("Could not retrieve updates: %1.").arg(updateFinder.errorString());
- d->setStatus(Failure, tr("Could not retrieve updates: %1.").arg(updateFinder.errorString()));
+ const RemotePackages &packages = d->remotePackages();
+ if (packages.isEmpty())
return false;
- }
-
- emit startUpdaterComponentsReset();
-
- d->clearUpdaterComponentLists();
- QMap<QString, QInstaller::Component*> components;
-
- Data data;
- data.components = &components;
- data.installedPackages = &installedPackages;
-
- bool importantUpdates = false;
- foreach (KDUpdater::Update *update, updates) {
- QScopedPointer<QInstaller::Component> component(new QInstaller::Component(this));
-
- data.package = update;
- component->loadDataFromUpdate(update);
- if (updateComponentData(data, component.data())) {
- // Keep a reference so we can resolve dependencies during update.
- d->m_updaterComponentsDeps.append(component.take());
-
- const QString isNew = update->data(scNewComponent).toString();
- if (isNew.toLower() != scTrue)
- continue;
-
- const QString &name = d->m_updaterComponentsDeps.last()->name();
- const QString replaces = data.package->data(scReplaces).toString();
- bool isValidUpdate = installedPackages.contains(name);
- if (!isValidUpdate && !replaces.isEmpty()) {
- const QStringList possibleNames = replaces.split(QLatin1String(","), QString::SkipEmptyParts);
- foreach (const QString &possibleName, possibleNames)
- isValidUpdate |= installedPackages.contains(possibleName);
- }
-
- if (!isValidUpdate)
- continue; // Update for not installed package found, skip it.
-
- const KDUpdater::PackageInfo &info = installedPackages.value(name);
- const QString updateVersion = update->data(scVersion).toString();
- if (KDUpdater::compareVersion(updateVersion, info.version) <= 0)
- continue;
-
- // It is quite possible that we may have already installed the update. Lets check the last
- // update date of the package and the release date of the update. This way we can compare and
- // figure out if the update has been installed or not.
- const QDate updateDate = update->data(scReleaseDate).toDate();
- if (info.lastUpdateDate > updateDate)
- continue;
-
- // this is not a dependency, it is a real update
- components.insert(name, d->m_updaterComponentsDeps.takeLast());
- }
- }
-
- // store all components that got a replacement
- storeReplacedComponents(components, data.replacementToExchangeables);
-
- // remove all unimportant components
- QList<QInstaller::Component*> updaterComponents = components.values();
- if (importantUpdates) {
- for (int i = updaterComponents.count() - 1; i >= 0; --i) {
- if (updaterComponents.at(i)->value(scImportant, scFalse).toLower() == scFalse)
- delete updaterComponents.takeAt(i);
- }
- }
-
- try {
- if (!updaterComponents.isEmpty()) {
- // load the scripts and append all components w/o parent to the direct list
- foreach (QInstaller::Component *component, updaterComponents) {
- component->loadComponentScript();
- component->setCheckState(Qt::Checked);
- appendRootComponent(component, UpdaterMode);
- }
-
- // after everything is set up, check installed components
- foreach (QInstaller::Component *component, d->m_updaterComponentsDeps) {
- if (component->isInstalled()) {
- // since we do not put them into the model, which would force a update of e.g. tri state
- // components, we have to check all installed components ourself
- component->setCheckState(Qt::Checked);
- }
- }
- } else {
- // we have no updates, no need to store possible dependencies
- qDeleteAll(d->m_updaterComponentsDeps);
- d->m_updaterComponentsDeps.clear();
- }
- } catch (const Error &error) {
- d->clearUpdaterComponentLists();
- emit finishUpdaterComponentsReset();
- d->setStatus(Failure, error.message());
- return false;
- }
-
- emit finishUpdaterComponentsReset();
- d->setStatus(Success);
-
- return true;
-}
-
-bool PackageManagerCore::fetchLocalPackagesTree()
-{
- d->setStatus(Running);
-
- if (!isPackageManager()) {
- d->setStatus(Failure, tr("Application not running in Package Manager mode!"));
- return false;
- }
-
- QHash<QString, KDUpdater::PackageInfo> installedPackages = d->localInstalledPackages();
- if (installedPackages.isEmpty()) {
- if (status() != Failure)
- d->setStatus(Failure, tr("No installed packages found."));
- return false;
- }
-
- emit startAllComponentsReset();
-
- d->clearAllComponentLists();
- QMap<QString, QInstaller::Component*> components;
-
- const QStringList &keys = installedPackages.keys();
- foreach (const QString &key, keys) {
- QScopedPointer<QInstaller::Component> component(new QInstaller::Component(this));
- component->loadDataFromPackageInfo(installedPackages.value(key));
- const QString &name = component->name();
- if (components.contains(name)) {
- qCritical("Could not register component! Component with identifier %s already registered.",
- qPrintable(name));
- continue;
- }
- components.insert(name, component.take());
- }
- // now append all components to their respective parents
- QMap<QString, QInstaller::Component*>::const_iterator it;
- for (it = components.begin(); it != components.end(); ++it) {
- QString id = it.key();
- QInstaller::Component *component = it.value();
- while (!id.isEmpty() && component->parentComponent() == 0) {
- id = id.section(QLatin1Char('.'), 0, -2);
- if (components.contains(id))
- components[id]->appendComponent(component);
- }
- }
-
- // append all components w/o parent to the direct list
- foreach (QInstaller::Component *component, components) {
- if (component->parentComponent() == 0)
- appendRootComponent(component, AllMode);
- }
-
- // now set the checked state for all components without child
- for (int i = 0; i < rootComponentCount(AllMode); ++i) {
- QList<Component*> children = rootComponent(i, AllMode)->childs();
- foreach (Component *child, children) {
- if (child->isCheckable() && !child->isTristate()) {
- if (child->isInstalled() || child->isDefault())
- child->setCheckState(Qt::Checked);
- }
- }
- }
-
- emit finishAllComponentsReset();
- d->setStatus(Success);
+ bool success = false;
+ if (runMode() == AllMode)
+ success = fetchAllPackages(packages, installedPackages);
+ else
+ success = fetchUpdaterPackages(packages, installedPackages);
- return true;
+ if (success)
+ d->setStatus(Success);
+ return success;
}
/*!
@@ -1685,7 +1489,7 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo
const QStringList components = replaces.split(QLatin1Char(','), QString::SkipEmptyParts);
foreach (const QString &componentName, components) {
if (data.installedPackages->contains(componentName)) {
- if (runMode() == AllMode) {
+ if (data.runMode == AllMode) {
component->setInstalled();
component->setValue(scInstalledVersion, data.package->data(scVersion).toString());
}
@@ -1718,20 +1522,185 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo
return true;
}
-void PackageManagerCore::storeReplacedComponents(QMap<QString, Component*> &components,
- const QHash<Component*, QStringList> &replacementToExchangeables)
+void PackageManagerCore::storeReplacedComponents(QMap<QString, Component*> &components, const struct Data &data)
{
QHash<Component*, QStringList>::const_iterator it;
// remeber all components that got a replacement, requierd for uninstall
- for (it = replacementToExchangeables.constBegin(); it != replacementToExchangeables.constEnd(); ++it) {
+ for (it = data.replacementToExchangeables.constBegin(); it != data.replacementToExchangeables.constEnd(); ++it) {
foreach (const QString &componentName, it.value()) {
Component *component = components.take(componentName);
- if (!component && !d->componentsToReplace().contains(componentName)) {
+ if (!component && !d->componentsToReplace(data.runMode).contains(componentName)) {
component = new Component(this);
component->setValue(scName, componentName);
}
if (component)
- d->componentsToReplace().insert(componentName, qMakePair(it.key(), component));
+ d->componentsToReplace(data.runMode).insert(componentName, qMakePair(it.key(), component));
}
}
}
+
+bool PackageManagerCore::fetchAllPackages(const RemotePackages &remotes, const LocalPackages &locals)
+{
+ emit startAllComponentsReset();
+
+ d->clearAllComponentLists();
+ QMap<QString, QInstaller::Component*> components;
+
+ Data data;
+ data.runMode = AllMode;
+ data.components = &components;
+ data.installedPackages = &locals;
+
+ foreach (KDUpdater::Update *package, remotes) {
+ QScopedPointer<QInstaller::Component> component(new QInstaller::Component(this));
+
+ data.package = package;
+ component->loadDataFromUpdate(package);
+ if (updateComponentData(data, component.data())) {
+ const QString name = component->name();
+ components.insert(name, component.take());
+ }
+ }
+
+ // store all components that got a replacement
+ storeReplacedComponents(components, data);
+
+ try {
+ // append all components to their respective parents
+ for (QMap<QString, Component*>::const_iterator it = components.begin(); it != components.end(); ++it) {
+ QString id = it.key();
+ QInstaller::Component *component = it.value();
+ while (!id.isEmpty() && component->parentComponent() == 0) {
+ id = id.section(QLatin1Char('.'), 0, -2);
+ if (components.contains(id))
+ components[id]->appendComponent(component);
+ }
+ }
+
+ // append all components w/o parent to the direct list
+ foreach (QInstaller::Component *component, components) {
+ if (component->parentComponent() == 0)
+ appendRootComponent(component, AllMode);
+ }
+
+ // after everything is set up, load the scripts
+ foreach (QInstaller::Component *component, components)
+ component->loadComponentScript();
+
+ // set the checked state for all components without child
+ for (int i = 0; i < rootComponentCount(AllMode); ++i) {
+ QList<Component*> children = rootComponent(i, AllMode)->childs();
+ foreach (Component *child, children) {
+ if (child->isCheckable() && !child->isTristate()) {
+ if (child->isInstalled() || child->isDefault())
+ child->setCheckState(Qt::Checked);
+ }
+ }
+ }
+ } catch (const Error &error) {
+ d->clearAllComponentLists();
+ emit finishAllComponentsReset();
+ d->setStatus(Failure, error.message());
+ return false;
+ }
+
+ emit finishAllComponentsReset();
+ return true;
+}
+
+bool PackageManagerCore::fetchUpdaterPackages(const RemotePackages &remotes, const LocalPackages &locals)
+{
+ emit startUpdaterComponentsReset();
+
+ d->clearUpdaterComponentLists();
+ QMap<QString, QInstaller::Component*> components;
+
+ Data data;
+ data.runMode = UpdaterMode;
+ data.components = &components;
+ data.installedPackages = &locals;
+
+ foreach (KDUpdater::Update *update, remotes) {
+ QScopedPointer<QInstaller::Component> component(new QInstaller::Component(this));
+
+ data.package = update;
+ component->loadDataFromUpdate(update);
+ if (updateComponentData(data, component.data())) {
+ // Keep a reference so we can resolve dependencies during update.
+ d->m_updaterComponentsDeps.append(component.take());
+
+ const QString isNew = update->data(scNewComponent).toString();
+ if (isNew.toLower() != scTrue)
+ continue;
+
+ const QString &name = d->m_updaterComponentsDeps.last()->name();
+ const QString replaces = data.package->data(scReplaces).toString();
+
+ bool isValidUpdate = locals.contains(name);
+ if (!isValidUpdate && !replaces.isEmpty()) {
+ const QStringList possibleNames = replaces.split(QLatin1String(","), QString::SkipEmptyParts);
+ foreach (const QString &possibleName, possibleNames)
+ isValidUpdate |= locals.contains(possibleName);
+ }
+
+ if (!isValidUpdate)
+ continue; // Update for not installed package found, skip it.
+
+ const KDUpdater::PackageInfo &info = locals.value(name);
+ const QString updateVersion = update->data(scVersion).toString();
+ if (KDUpdater::compareVersion(updateVersion, info.version) <= 0)
+ continue;
+
+ // It is quite possible that we may have already installed the update. Lets check the last
+ // update date of the package and the release date of the update. This way we can compare and
+ // figure out if the update has been installed or not.
+ const QDate updateDate = update->data(scReleaseDate).toDate();
+ if (info.lastUpdateDate > updateDate)
+ continue;
+
+ // this is not a dependency, it is a real update
+ components.insert(name, d->m_updaterComponentsDeps.takeLast());
+ }
+ }
+
+ // store all components that got a replacement
+ storeReplacedComponents(components, data);
+
+ try {
+ // remove all unimportant updates
+ const QStringList &keys = components.keys();
+ foreach (const QString &key, keys) {
+ if (components.value(key)->value(scImportant, scFalse).toLower() == scFalse)
+ delete components.take(key);
+ }
+
+ if (!components.isEmpty()) {
+ // load the scripts and append all components w/o parent to the direct list
+ foreach (QInstaller::Component *component, components) {
+ component->loadComponentScript();
+ component->setCheckState(Qt::Checked);
+ appendRootComponent(component, UpdaterMode);
+ }
+
+ // after everything is set up, check installed components
+ foreach (QInstaller::Component *component, d->m_updaterComponentsDeps) {
+ if (component->isInstalled()) {
+ // since we do not put them into the model, which would force a update of e.g. tri state
+ // components, we have to check all installed components ourself
+ component->setCheckState(Qt::Checked);
+ }
+ }
+ } else {
+ // we have no updates, no need to store possible dependencies
+ d->clearUpdaterComponentLists();
+ }
+ } catch (const Error &error) {
+ d->clearUpdaterComponentLists();
+ emit finishUpdaterComponentsReset();
+ d->setStatus(Failure, error.message());
+ return false;
+ }
+
+ emit finishUpdaterComponentsReset();
+ return true;
+}
diff --git a/installerbuilder/libinstaller/packagemanagercore.h b/installerbuilder/libinstaller/packagemanagercore.h
index 02cf1d077..4e9aadffb 100644
--- a/installerbuilder/libinstaller/packagemanagercore.h
+++ b/installerbuilder/libinstaller/packagemanagercore.h
@@ -56,7 +56,10 @@ class INSTALLER_EXPORT PackageManagerCore : public QObject
Q_ENUMS(Status WizardPage)
Q_PROPERTY(int status READ status NOTIFY statusChanged)
+ typedef QList<KDUpdater::Update*> RemotePackages;
typedef QList<KDUpdater::UpdateOperation*> Operations;
+ typedef QHash<QString, KDUpdater::PackageInfo> LocalPackages;
+
public:
explicit PackageManagerCore();
explicit PackageManagerCore(qint64 magicmaker, const Operations &oldOperations = Operations());
@@ -94,9 +97,8 @@ public:
static bool noForceInstallation();
static void setNoForceInstallation(bool value);
- bool fetchAllPackages();
- bool fetchUpdaterPackages();
bool fetchLocalPackagesTree();
+ bool fetchRemotePackagesTree();
bool run();
RunMode runMode() const;
@@ -245,16 +247,20 @@ Q_SIGNALS:
private:
struct Data {
+ RunMode runMode;
KDUpdater::Update *package;
QMap<QString, Component*> *components;
+ const LocalPackages *installedPackages;
QHash<Component*, QStringList> replacementToExchangeables;
- QHash<QString, KDUpdater::PackageInfo> *installedPackages;
};
+
bool updateComponentData(struct Data &data, QInstaller::Component *component);
+ void storeReplacedComponents(QMap<QString, Component*> &components, const struct Data &data);
+ bool fetchAllPackages(const RemotePackages &remotePackages, const LocalPackages &localPackages);
+ bool fetchUpdaterPackages(const RemotePackages &remotePackages, const LocalPackages &localPackages);
+
static Component *subComponentByName(const QInstaller::PackageManagerCore *installer, const QString &name,
const QString &version = QString(), Component *check = 0);
- void storeReplacedComponents(QMap<QString, Component*> &components,
- const QHash<Component*, QStringList> &replacementToExchangeables);
private:
PackageManagerCorePrivate *const d;
diff --git a/installerbuilder/libinstaller/packagemanagercore_p.cpp b/installerbuilder/libinstaller/packagemanagercore_p.cpp
index 11323143b..09d7a77f5 100644
--- a/installerbuilder/libinstaller/packagemanagercore_p.cpp
+++ b/installerbuilder/libinstaller/packagemanagercore_p.cpp
@@ -47,8 +47,8 @@
#include <KDToolsCore/KDSaveFile>
#include <KDToolsCore/KDSelfRestarter>
-
#include <KDUpdater/KDUpdater>
+#include <KDUpdater/UpdateOperation>
#include <QtCore/QtConcurrentRun>
#include <QtCore/QCoreApplication>
@@ -151,8 +151,11 @@ static void deferredRename(const QString &oldName, const QString &newName, bool
// -- PackageManagerCorePrivate
PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core)
- : m_FSEngineClientHandler(0)
+ : m_updateFinder(0)
+ , m_FSEngineClientHandler(0)
, m_core(core)
+ , m_repoMetaInfoJob(0)
+ , m_updates(false)
, m_repoFetched(false)
, m_updateSourcesAdded(false)
{
@@ -160,7 +163,8 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core)
PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, qint64 magicInstallerMaker,
const QList<KDUpdater::UpdateOperation*> &performedOperations)
- : m_FSEngineClientHandler(initFSEngineClientHandler())
+ : m_updateFinder(0)
+ , m_FSEngineClientHandler(initFSEngineClientHandler())
, m_status(PackageManagerCore::Unfinished)
, m_forceRestart(false)
, m_testChecksum(false)
@@ -169,9 +173,11 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, q
, m_needToWriteUninstaller(false)
, m_performedOperationsOld(performedOperations)
, m_core(core)
- , m_magicBinaryMarker(magicInstallerMaker)
+ , m_repoMetaInfoJob(0)
+ , m_updates(false)
, m_repoFetched(false)
, m_updateSourcesAdded(false)
+ , m_magicBinaryMarker(magicInstallerMaker)
{
connect(this, SIGNAL(installationStarted()), m_core, SIGNAL(installationStarted()));
connect(this, SIGNAL(installationFinished()), m_core, SIGNAL(installationFinished()));
@@ -191,6 +197,7 @@ PackageManagerCorePrivate::~PackageManagerCorePrivate()
// check for fake installer case
if (m_FSEngineClientHandler)
m_FSEngineClientHandler->setActive(false);
+ delete m_updateFinder;
}
/*!
@@ -281,9 +288,9 @@ void PackageManagerCorePrivate::clearUpdaterComponentLists()
m_componentsToReplaceUpdaterMode.clear();
}
-QHash<QString, QPair<Component*, Component*> > &PackageManagerCorePrivate::componentsToReplace()
+QHash<QString, QPair<Component*, Component*> > &PackageManagerCorePrivate::componentsToReplace(RunMode mode)
{
- return m_core->runMode() == AllMode ? m_componentsToReplaceAllMode : m_componentsToReplaceUpdaterMode;
+ return mode == AllMode ? m_componentsToReplaceAllMode : m_componentsToReplaceUpdaterMode;
}
void PackageManagerCorePrivate::initialize()
@@ -372,13 +379,16 @@ void PackageManagerCorePrivate::initialize()
m_updaterApplication.updateSourcesInfo()->setModified(false);
}
- if (!m_repoFetched) {
- m_repoMetaInfoJob.clear();
- m_repoMetaInfoJob =
- QSharedPointer<GetRepositoriesMetaInfoJob>(new GetRepositoriesMetaInfoJob(m_settings.publicKey()));
- connect(m_repoMetaInfoJob.data(), SIGNAL(infoMessage(KDJob*, QString)), m_core,
+ if (!m_repoMetaInfoJob) {
+ m_repoMetaInfoJob = new GetRepositoriesMetaInfoJob(m_settings.publicKey());
+ connect(m_repoMetaInfoJob, SIGNAL(infoMessage(KDJob*, QString)), m_core,
SIGNAL(metaJobInfoMessage(KDJob*, QString)));
}
+ if (!m_updateFinder) {
+ m_updateFinder = new KDUpdater::UpdateFinder(&m_updaterApplication);
+ m_updateFinder->setAutoDelete(false);
+ m_updateFinder->setUpdateType(KDUpdater::PackageUpdate | KDUpdater::NewPackage);
+ }
}
QString PackageManagerCorePrivate::installerBinaryPath() const
@@ -1558,7 +1568,7 @@ void PackageManagerCorePrivate::runUndoOperations(const QList<KDUpdater::UpdateO
if (!componentName.isEmpty()) {
Component *component = m_core->componentByName(componentName);
if (!component)
- component = componentsToReplace().value(componentName).second;
+ component = componentsToReplace(m_core->runMode()).value(componentName).second;
if (component) {
component->setUninstalled();
packages.removePackage(component->name());
@@ -1581,6 +1591,53 @@ void PackageManagerCorePrivate::runUndoOperations(const QList<KDUpdater::UpdateO
packages.writeToDisk();
}
+PackageManagerCore::RemotePackages PackageManagerCorePrivate::remotePackages()
+{
+ if (m_updates)
+ return m_updateFinder->updates();
+
+ m_updates = false;
+
+ m_updateFinder->run();
+
+ if (m_updateFinder->updates().isEmpty()) {
+ verbose() << tr("Could not retrieve remote tree: %1.").arg(m_updateFinder->errorString());
+ setStatus(PackageManagerCore::Failure, tr("Could not retrieve remote tree: %1.")
+ .arg(m_updateFinder->errorString()));
+ return PackageManagerCore::RemotePackages();
+ }
+
+ m_updates = true;
+ return m_updateFinder->updates();
+}
+
+/*!
+ Returns a hash containing the installed package name and it's associated package information. If
+ the application is running in installer mode or the local components file could not be parsed, the
+ hash is empty.
+*/
+PackageManagerCore::LocalPackages PackageManagerCorePrivate::localInstalledPackages()
+{
+ PackageManagerCore::LocalPackages installedPackages;
+
+ KDUpdater::PackagesInfo &packagesInfo = *m_updaterApplication.packagesInfo();
+ if (!isInstaller()) {
+ if (!packagesInfo.isValid()) {
+ packagesInfo.setFileName(componentsXmlPath());
+ packagesInfo.setApplicationName(m_settings.applicationName());
+ packagesInfo.setApplicationVersion(m_settings.applicationVersion());
+ }
+
+ if (packagesInfo.error() != KDUpdater::PackagesInfo::NoError)
+ setStatus(PackageManagerCore::Failure, tr("Failure to read packages from: %1.").arg(componentsXmlPath()));
+
+ foreach (const KDUpdater::PackageInfo &info, packagesInfo.packageInfos())
+ installedPackages.insert(info.name, info);
+ }
+
+ return installedPackages;
+}
+
bool PackageManagerCorePrivate::fetchMetaInformationFromRepositories()
{
if (m_repoFetched)
@@ -1596,6 +1653,7 @@ bool PackageManagerCorePrivate::fetchMetaInformationFromRepositories()
m_repoMetaInfoJob->waitForFinished();
} catch (Error &error) {
verbose() << tr("Could not retrieve meta information: %1").arg(error.message()) << std::endl;
+ setStatus(PackageManagerCore::Failure, tr("Could not retrieve meta information: %1").arg(error.message()));
return m_repoFetched;
}
@@ -1667,31 +1725,4 @@ bool PackageManagerCorePrivate::addUpdateResourcesFromRepositories(bool parseChe
return m_updateSourcesAdded;
}
-/*!
- Returns a hash containing the installed package name and it's associated package information. If
- the application is running in installer mode or the local components file could not be parsed, the
- hash is empty.
-*/
-QHash<QString, KDUpdater::PackageInfo> PackageManagerCorePrivate::localInstalledPackages()
-{
- QHash<QString, KDUpdater::PackageInfo> installedPackages;
-
- KDUpdater::PackagesInfo &packagesInfo = *m_updaterApplication.packagesInfo();
- if (!isInstaller()) {
- if (!packagesInfo.isValid()) {
- packagesInfo.setFileName(componentsXmlPath());
- packagesInfo.setApplicationName(m_settings.applicationName());
- packagesInfo.setApplicationVersion(m_settings.applicationVersion());
- }
-
- if (packagesInfo.error() != KDUpdater::PackagesInfo::NoError)
- setStatus(PackageManagerCore::Failure, tr("Failure to read packages from: %1.").arg(componentsXmlPath()));
-
- foreach (const KDUpdater::PackageInfo &info, packagesInfo.packageInfos())
- installedPackages.insert(info.name, info);
- }
-
- return installedPackages;
-}
-
} // QInstaller
diff --git a/installerbuilder/libinstaller/packagemanagercore_p.h b/installerbuilder/libinstaller/packagemanagercore_p.h
index 0d58ef690..3a59c9e83 100644
--- a/installerbuilder/libinstaller/packagemanagercore_p.h
+++ b/installerbuilder/libinstaller/packagemanagercore_p.h
@@ -50,7 +50,7 @@ QT_FORWARD_DECLARE_CLASS(QFile)
QT_FORWARD_DECLARE_CLASS(QFileInfo)
namespace KDUpdater {
- class Application;
+ class UpdateFinder;
class UpdateOperation;
}
@@ -102,7 +102,7 @@ public:
void clearAllComponentLists();
void clearUpdaterComponentLists();
- QHash<QString, QPair<Component*, Component*> > &componentsToReplace();
+ QHash<QString, QPair<Component*, Component*> > &componentsToReplace(RunMode mode);
void runInstaller();
bool isInstaller() const;
@@ -151,6 +151,7 @@ signals:
void uninstallationFinished();
public:
+ KDUpdater::UpdateFinder *m_updateFinder;
KDUpdater::Application m_updaterApplication;
FSEngineClientHandler *m_FSEngineClientHandler;
@@ -188,17 +189,20 @@ private:
void runUndoOperations(const QList<KDUpdater::UpdateOperation*> &undoOperations,
double undoOperationProgressSize, bool adminRightsGained, bool deleteOperation);
+ PackageManagerCore::RemotePackages remotePackages();
+ PackageManagerCore::LocalPackages localInstalledPackages();
+
bool fetchMetaInformationFromRepositories();
bool addUpdateResourcesFromRepositories(bool parseChecksum);
- QHash<QString, KDUpdater::PackageInfo> localInstalledPackages();
private:
PackageManagerCore *m_core;
- qint64 m_magicBinaryMarker;
+ GetRepositoriesMetaInfoJob *m_repoMetaInfoJob;
+ bool m_updates;
bool m_repoFetched;
bool m_updateSourcesAdded;
- QSharedPointer<GetRepositoriesMetaInfoJob> m_repoMetaInfoJob;
+ qint64 m_magicBinaryMarker;
// < name (component to replace), < replacement component, component to replace > >
QHash<QString, QPair<Component*, Component*> > m_componentsToReplaceAllMode;
diff --git a/installerbuilder/libinstaller/updater.cpp b/installerbuilder/libinstaller/updater.cpp
index e4962bede..58e4448f1 100644
--- a/installerbuilder/libinstaller/updater.cpp
+++ b/installerbuilder/libinstaller/updater.cpp
@@ -72,7 +72,7 @@ bool Updater::checkForUpdates()
core.setUpdater();
PackageManagerCore::setVirtualComponentsVisible(true);
- if (core.fetchUpdaterPackages()) {
+ if (core.fetchRemotePackagesTree()) {
const QList<QInstaller::Component*> components = core.components(true, UpdaterMode);
if (components.isEmpty()) {