From 84c8a408327f7386905d7faa4c682618cbf46455 Mon Sep 17 00:00:00 2001 From: kh1 Date: Wed, 4 Sep 2013 20:28:06 +0200 Subject: Add support to update only new components. Task-number: QTIFW-234 Change-Id: I49f1714925e7c83e06c86c9022cc8ae8ff01a840 Reviewed-by: Niels Weber Reviewed-by: Iikka Eklund --- tools/repogen/repogen.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/repogen/repogen.cpp b/tools/repogen/repogen.cpp index 9f0452b92..e0e0a88c0 100644 --- a/tools/repogen/repogen.cpp +++ b/tools/repogen/repogen.cpp @@ -43,10 +43,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -73,12 +75,16 @@ static void printUsage() std::cout << " --update Update a set of existing components (defined by " << std::endl; std::cout << " --include or --exclude) in the repository" << std::endl; + std::cout << " --update-new-components Update a set of existing components (defined by " << std::endl; + std::cout << " --include or --exclude) in the repository with all new components" + << std::endl; + std::cout << " -v|--verbose Verbose output" << std::endl; std::cout << std::endl; std::cout << "Example:" << std::endl; - std::cout << " " << appName << " -p ../examples/packages -u " - "http://www.example.com:8080 repository/" << std::endl; + std::cout << " " << appName << " -p ../examples/packages -u http://www.example.com:8080 repository/" + << std::endl; } static int printErrorAndUsageAndExit(const QString &err) @@ -104,6 +110,7 @@ int main(int argc, char** argv) QString packagesDir; QInstallerTools::FilterType filterType = QInstallerTools::Exclude; bool remove = false; + bool updateExistingRepositoryWithNewComponents = false; //TODO: use a for loop without removing values from args like it is in binarycreator.cpp //for (QStringList::const_iterator it = args.begin(); it != args.end(); ++it) { @@ -133,6 +140,9 @@ int main(int argc, char** argv) } else if (args.first() == QLatin1String("--update")) { args.removeFirst(); updateExistingRepository = true; + } else if (args.first() == QLatin1String("--update-new-components")) { + args.removeFirst(); + updateExistingRepositoryWithNewComponents = true; } else if (args.first() == QLatin1String("-p") || args.first() == QLatin1String("--packages")) { args.removeFirst(); if (args.isEmpty()) { @@ -168,16 +178,17 @@ int main(int argc, char** argv) return 1; } - if (remove && updateExistingRepository) { - throw QInstaller::Error(QObject::tr("Argument -r|--remove and --update are mutually " - "exclusive!")); + const bool update = updateExistingRepository || updateExistingRepositoryWithNewComponents; + if (remove && update) { + throw QInstaller::Error(QObject::tr("Argument -r|--remove and --update|--update-new-components " + "are mutually exclusive!")); } const QString repositoryDir = QInstallerTools::makePathAbsolute(args.first()); if (remove) QInstaller::removeDirectory(repositoryDir); - if (!updateExistingRepository && QFile::exists(repositoryDir) && !QDir(repositoryDir).entryList( + if (!update && QFile::exists(repositoryDir) && !QDir(repositoryDir).entryList( QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) { throw QInstaller::Error(QObject::tr("Repository target folder %1 already exists!") @@ -186,6 +197,52 @@ int main(int argc, char** argv) QInstallerTools::PackageInfoVector packages = QInstallerTools::createListOfPackages(packagesDir, &filteredPackages, filterType); + + if (updateExistingRepositoryWithNewComponents) { + QDomDocument doc; + QFile file(repositoryDir + QLatin1String("/Updates.xml")); + if (file.open(QFile::ReadOnly) && doc.setContent(&file)) { + const QDomElement root = doc.documentElement(); + if (root.tagName() != QLatin1String("Updates")) + throw QInstaller::Error(QObject::tr("Invalid content in '%1'.").arg(file.fileName())); + file.close(); // close the file, we read the content already + + // read the already existing updates xml content + const QDomNodeList children = root.childNodes(); + QHash hash; + for (int i = 0; i < children.count(); ++i) { + const QDomElement el = children.at(i).toElement(); + if ((!el.isNull()) && (el.tagName() == QLatin1String("PackageUpdate"))) { + QInstallerTools::PackageInfo info; + const QDomNodeList c2 = el.childNodes(); + for (int j = 0; j < c2.count(); ++j) { + if (c2.at(j).toElement().tagName() == scName) + info.name = c2.at(j).toElement().text(); + else if (c2.at(j).toElement().tagName() == scRemoteVersion) + info.version = c2.at(j).toElement().text(); + } + hash.insert(info.name, info); + } + } + + // remove all components that have no update (decision based on the version tag) + for (int i = packages.count() - 1; i >= 0; --i) { + const QInstallerTools::PackageInfo info = packages.at(i); + if (!hash.contains(info.name)) + continue; // the component is not there, keep it + + if (KDUpdater::compareVersion(info.version, hash.value(info.name).version) < 1) + packages.remove(i); // the version did not change, no need to update the component + } + + if (packages.isEmpty()) { + std::cout << QString::fromLatin1("Could not find new components to update '%1'.") + .arg(repositoryDir); + return EXIT_SUCCESS; + } + } + } + QHash pathToVersionMapping = QInstallerTools::buildPathToVersionMapping(packages); foreach (const QInstallerTools::PackageInfo &package, packages) { -- cgit v1.2.3