diff options
Diffstat (limited to 'tools/common/repositorygen.cpp')
-rw-r--r-- | tools/common/repositorygen.cpp | 448 |
1 files changed, 204 insertions, 244 deletions
diff --git a/tools/common/repositorygen.cpp b/tools/common/repositorygen.cpp index 1549fb896..2af72f0cb 100644 --- a/tools/common/repositorygen.cpp +++ b/tools/common/repositorygen.cpp @@ -42,17 +42,17 @@ #include <fileutils.h> #include <errors.h> +#include <globals.h> #include <lib7z_facade.h> #include <settings.h> #include <qinstallerglobal.h> #include <utils.h> +#include <scriptengine.h> #include <kdupdater.h> #include <QtCore/QDirIterator> -#include <QtScript/QScriptEngine> - #include <QtXml/QDomDocument> #include <iostream> @@ -72,6 +72,33 @@ void QInstallerTools::printRepositoryGenOptions() std::cout << " --ignore-invalid-packages Ignore all invalid packages instead of aborting." << std::endl; } +QString QInstallerTools::makePathAbsolute(const QString &path) +{ + if (QFileInfo(path).isRelative()) + return QDir::current().absoluteFilePath(path); + return path; +} + +void QInstallerTools::copyWithException(const QString &source, const QString &target, const QString &kind) +{ + qDebug() << QString::fromLatin1("Copying associated %1 file '%2'").arg(kind, source); + + const QFileInfo targetFileInfo(target); + if (!targetFileInfo.dir().exists()) + QInstaller::mkpath(targetFileInfo.absolutePath()); + + QFile sourceFile(source); + if (!sourceFile.copy(target)) { + qDebug() << "failed!\n"; + throw QInstaller::Error(QString::fromLatin1("Could not copy the %1 file from\n'%2' to '%3'\nError: " + "'%4'.").arg(kind, source, target, + /* in case of an existing target the error String does not show the file */ + (targetFileInfo.exists() ? QLatin1String("Target already exist.") : sourceFile.errorString()))); + } + + qDebug() << "done.\n"; +} + void QInstallerTools::compressPaths(const QStringList &paths, const QString &archivePath) { QFile archive(archivePath); @@ -79,91 +106,92 @@ void QInstallerTools::compressPaths(const QStringList &paths, const QString &arc Lib7z::createArchive(&archive, paths); } -void QInstallerTools::compressMetaDirectories(const QString &repoDir) +static QStringList copyFilesFromNode(const QString &parentNode, const QString &childNode, const QString &attr, + const QString &kind, const QDomNode &package, const PackageInfo &info, const QString &targetDir) { - QDir dir(repoDir); - const QStringList sub = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); - foreach (const QString &i, sub) { - QDir sd(dir); - sd.cd(i); - const QString absPath = sd.absolutePath(); - const QString fn = QLatin1String("meta.7z"); - const QString tmpTarget = repoDir + QLatin1String("/") +fn; - compressPaths(QStringList() << absPath, tmpTarget); - QFile tmp(tmpTarget); - const QString finalTarget = absPath + QLatin1String("/") + fn; - if (!tmp.rename(finalTarget)) { - throw QInstaller::Error(QString::fromLatin1("Could not move file from '%1' to '%2'").arg(tmpTarget, - finalTarget)); + QStringList copiedFiles; + const QDomNodeList nodes = package.firstChildElement(parentNode).childNodes(); + for (int i = 0; i < nodes.count(); ++i) { + const QDomNode node = nodes.at(i); + if (node.nodeName() != childNode) + continue; + + const QDir dir(QString::fromLatin1("%1/meta").arg(info.directory)); + const QString filter = attr.isEmpty() ? node.toElement().text() : node.toElement().attribute(attr); + const QStringList files = dir.entryList(QStringList(filter), QDir::Files); + if (files.isEmpty()) { + throw QInstaller::Error(QString::fromLatin1("Couldn't find any %1 matching '%2' " + "while copying %1 of '%3'.").arg(kind, filter, info.name)); + } + + foreach (const QString &file, files) { + const QString source(QString::fromLatin1("%1/meta/%2").arg(info.directory, file)); + const QString target(QString::fromLatin1("%1/%2/%3").arg(targetDir, info.name, file)); + copyWithException(source, target, kind); + copiedFiles.append(file); } } + return copiedFiles; } -void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QString &dataDir, - const PackageInfoVector &packages, const QString &appName, const QString &appVersion, - const QString &redirectUpdateUrl) +void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &metaDataDir, + const PackageInfoVector &packages, const QString &appName, const QString &appVersion) { - QString metapath = outDir; - if (QFileInfo(metapath).isRelative()) - metapath = QDir::cleanPath(QDir::current().absoluteFilePath(metapath)); - qDebug() << "Generating meta data..."; - - if (!QFile::exists(metapath)) - QInstaller::mkpath(metapath); + const QString targetDir = makePathAbsolute(_targetDir); + if (!QFile::exists(targetDir)) + QInstaller::mkpath(targetDir); QDomDocument doc; QDomElement root; - // use existing Updates.xml, if any - QFile existingUpdatesXml(QFileInfo(dataDir, QLatin1String("Updates.xml")).absoluteFilePath()); - if (!existingUpdatesXml.open(QIODevice::ReadOnly) || !doc.setContent(&existingUpdatesXml)) { - root = doc.createElement(QLatin1String("Updates")); - root.appendChild(doc.createElement(QLatin1String("ApplicationName"))).appendChild( - doc.createTextNode(appName)); - root.appendChild(doc.createElement(QLatin1String("ApplicationVersion"))).appendChild( - doc.createTextNode(appVersion)); - root.appendChild(doc.createElement(QLatin1String("Checksum"))).appendChild( - doc.createTextNode(QLatin1String("true"))); - if (!redirectUpdateUrl.isEmpty()) { - root.appendChild(doc.createElement(QLatin1String("RedirectUpdateUrl"))).appendChild( - doc.createTextNode(redirectUpdateUrl)); + QFile existingUpdatesXml(QFileInfo(metaDataDir, QLatin1String("Updates.xml")).absoluteFilePath()); + if (existingUpdatesXml.open(QIODevice::ReadOnly) && doc.setContent(&existingUpdatesXml)) { + root = doc.documentElement(); + // remove entry for this component from existing Updates.xml, if found + foreach (const PackageInfo &info, packages) { + const QDomNodeList packageNodes = root.childNodes(); + for (int i = packageNodes.count() - 1; i >= 0; --i) { + const QDomNode node = packageNodes.at(i); + if (node.nodeName() != QLatin1String("PackageUpdate")) + continue; + if (node.firstChildElement(QLatin1String("Name")).text() != info.name) + continue; + root.removeChild(node); + } } + existingUpdatesXml.close(); } else { - root = doc.documentElement(); + root = doc.createElement(QLatin1String("Updates")); + root.appendChild(doc.createElement(QLatin1String("ApplicationName"))).appendChild(doc + .createTextNode(appName)); + root.appendChild(doc.createElement(QLatin1String("ApplicationVersion"))).appendChild(doc + .createTextNode(appVersion)); + root.appendChild(doc.createElement(QLatin1String("Checksum"))).appendChild(doc + .createTextNode(QLatin1String("true"))); } - for (PackageInfoVector::const_iterator it = packages.begin(); it != packages.end(); ++it) { - const QString packageXmlPath = QString::fromLatin1("%1/meta/package.xml").arg(it->directory); - qDebug() << QString::fromLatin1("\tGenerating meta data for package %1 using %2.").arg( - it->name, packageXmlPath); + foreach (const PackageInfo &info, packages) { + if (!QDir(targetDir).mkpath(info.name)) + throw QInstaller::Error(QString::fromLatin1("Could not create directory '%1'.").arg(info.name)); - // remove existing entry for this component from existing Updates.xml - const QDomNodeList packageNodes = root.childNodes(); - for (int i = 0; i < packageNodes.count(); ++i) { - const QDomNode node = packageNodes.at(i); - if (node.nodeName() != QLatin1String("PackageUpdate")) - continue; - if (node.firstChildElement(QLatin1String("Name")).text() != it->name) - continue; - root.removeChild(node); - --i; - } + const QString packageXmlPath = QString::fromLatin1("%1/meta/package.xml").arg(info.directory); + qDebug() << QString::fromLatin1("Copy meta data for package '%1' using '%2'.").arg(info.name, + packageXmlPath); - QDomDocument packageXml; QFile file(packageXmlPath); QInstaller::openForRead(&file, packageXmlPath); + QString errMsg; - int col = 0; int line = 0; - if (!packageXml.setContent(&file, &errMsg, &line, &col)) { + int column = 0; + QDomDocument packageXml; + if (!packageXml.setContent(&file, &errMsg, &line, &column)) { throw QInstaller::Error(QString::fromLatin1("Could not parse '%1': line: %2, column: %3: %4 (%5)") - .arg(packageXmlPath, QString::number(line), QString::number(col), errMsg, it->name)); + .arg(packageXmlPath).arg(line).arg(column).arg(errMsg, info.name)); } - const QDomNode package = packageXml.firstChildElement(QLatin1String("Package")); QDomElement update = doc.createElement(QLatin1String("PackageUpdate")); - QDomElement nameElement = doc.createElement(QLatin1String("Name")); - nameElement.appendChild(doc.createTextNode(it->name)); - update.appendChild(nameElement); + QDomNode nameElement = update.appendChild(doc.createElement(QLatin1String("Name"))); + nameElement.appendChild(doc.createTextNode(info.name)); // list of current unused or later transformed tags QStringList blackList; @@ -173,6 +201,8 @@ void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QSt bool foundDefault = false; bool foundVirtual = false; bool foundDisplayName = false; + bool foundDownloadableArchives = false; + const QDomNode package = packageXml.firstChildElement(QLatin1String("Package")); const QDomNodeList childNodes = package.childNodes(); for (int i = 0; i < childNodes.count(); ++i) { const QDomNode node = childNodes.at(i); @@ -184,16 +214,17 @@ void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QSt foundVirtual = true; if (key == QLatin1String("DisplayName")) foundDisplayName = true; + if (key == QLatin1String("DownloadableArchives")) + foundDownloadableArchives = true; if (node.isComment() || blackList.contains(key)) continue; // just skip comments and some tags... - const QString value = node.toElement().text(); QDomElement element = doc.createElement(key); - for (int i = 0; i < node.attributes().size(); i++) { - element.setAttribute(node.attributes().item(i).toAttr().name(), - node.attributes().item(i).toAttr().value()); + for (int j = 0; j < node.attributes().size(); ++j) { + element.setAttribute(node.attributes().item(j).toAttr().name(), + node.attributes().item(j).toAttr().value()); } - update.appendChild(element).appendChild(doc.createTextNode(value)); + update.appendChild(element).appendChild(doc.createTextNode(node.toElement().text())); } if (foundDefault && foundVirtual) { @@ -202,10 +233,10 @@ void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QSt } if (!foundDisplayName) { - qWarning() << "No DisplayName tag found, using component Name instead."; + qWarning() << QString::fromLatin1("No DisplayName tag found at '%1', using component Name instead." + ).arg(info.name); QDomElement displayNameElement = doc.createElement(QLatin1String("DisplayName")); - displayNameElement.appendChild(doc.createTextNode(it->name)); - update.appendChild(displayNameElement); + update.appendChild(displayNameElement).appendChild(doc.createTextNode(info.name)); } // get the size of the data @@ -213,19 +244,17 @@ void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QSt quint64 compressedComponentSize = 0; const QDir::Filters filters = QDir::Files | QDir::NoDotAndDotDot; - const QDir cmpDataDir = QString::fromLatin1("%1/%2/data").arg(dataDir, it->name); - const QFileInfoList entries = cmpDataDir.exists() ? cmpDataDir.entryInfoList(filters | QDir::Dirs) - : QDir(QString::fromLatin1("%1/%2").arg(dataDir, it->name)).entryInfoList(filters); - + const QDir dataDir = QString::fromLatin1("%1/%2/data").arg(metaDataDir, info.name); + const QFileInfoList entries = dataDir.exists() ? dataDir.entryInfoList(filters | QDir::Dirs) + : QDir(QString::fromLatin1("%1/%2").arg(metaDataDir, info.name)).entryInfoList(filters); + qDebug() << QString::fromLatin1("calculate size of directory: %1").arg(dataDir.absolutePath()); foreach (const QFileInfo &fi, entries) { - if (fi.isHidden()) - continue; - try { if (fi.isDir()) { QDirIterator recursDirIt(fi.filePath(), QDirIterator::Subdirectories); while (recursDirIt.hasNext()) { - const quint64 size = QFile(recursDirIt.next()).size(); + recursDirIt.next(); + const quint64 size = QInstaller::fileSize(recursDirIt.fileInfo()); componentSize += size; compressedComponentSize += size; } @@ -233,18 +262,20 @@ void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QSt // if it's an archive already, list its files and sum the uncompressed sizes QFile archive(fi.filePath()); compressedComponentSize += archive.size(); - archive.open(QIODevice::ReadOnly); - const QVector< Lib7z::File > files = Lib7z::listArchive(&archive); - for (QVector< Lib7z::File >::const_iterator fileIt = files.begin(); - fileIt != files.end(); ++fileIt) { - componentSize += fileIt->uncompressedSize; - } + QInstaller::openForRead(&archive, archive.fileName()); + + QVector<Lib7z::File>::const_iterator fileIt; + const QVector<Lib7z::File> files = Lib7z::listArchive(&archive); + for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) + componentSize += fileIt->uncompressedSize; } else { // otherwise just add its size - const quint64 size = fi.size(); + const quint64 size = QInstaller::fileSize(fi); componentSize += size; compressedComponentSize += size; } + } catch (const QInstaller::Error &error) { + qDebug() << error.message(); } catch(...) { // ignore, that's just about the sizes - and size doesn't matter, you know? } @@ -259,206 +290,128 @@ void QInstallerTools::generateMetaDataDirectory(const QString &outDir, const QSt root.appendChild(update); - if (!QDir(metapath).mkpath(it->name)) - throw QInstaller::Error(QString::fromLatin1("Could not create directory '%1'.").arg(it->name)); - - // copy scripts + // copy script file const QString script = package.firstChildElement(QLatin1String("Script")).text(); if (!script.isEmpty()) { - const QString fromLocation(QString::fromLatin1("%1/meta/%2").arg(it->directory, script)); - QString scriptContent; - QFile scriptFile(fromLocation); + QFile scriptFile(QString::fromLatin1("%1/meta/%2").arg(info.directory, script)); if (scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&scriptFile); scriptContent = in.readAll(); } + + // if the user isn't aware of the downloadable archives value we will add it automatically later + foundDownloadableArchives |= scriptContent.contains(QLatin1String("addDownloadableArchive")) + || scriptContent.contains(QLatin1String("removeDownloadableArchive")); + static QScriptEngine testScriptEngine; testScriptEngine.evaluate(scriptContent, scriptFile.fileName()); if (testScriptEngine.hasUncaughtException()) { - throw QInstaller::Error(QString::fromLatin1("Exception while loading the component script: '%1'") + throw QInstaller::Error(QString::fromLatin1("Exception while loading component script: '%1'") .arg(QInstaller::uncaughtExceptionString(&testScriptEngine, scriptFile.fileName()))); } - // added the xml tag RequiresAdminRights to the xml if somewhere addElevatedOperation is used + // add RequiresAdminRights tag to xml if addElevatedOperation is used somewhere if (scriptContent.contains(QLatin1String("addElevatedOperation"))) { - QDomElement requiresAdminRightsElement = - doc.createElement(QLatin1String("RequiresAdminRights")); - requiresAdminRightsElement.appendChild(doc.createTextNode(QLatin1String("true"))); + QDomElement element = doc.createElement(QLatin1String("RequiresAdminRights")); + element.appendChild(doc.createTextNode(QLatin1String("true"))); } - qDebug() << "\tCopying associated script" << script << "into the meta package..."; - QString toLocation(QString::fromLatin1("%1/%2/%3").arg(metapath, it->name, script)); - if (!scriptFile.copy(toLocation)) { - qDebug() << "failed!"; - throw QInstaller::Error(QString::fromLatin1("Could not copy the script '%1' to its target location '%2'.") - .arg(fromLocation, toLocation)); - } else { - qDebug() << "\tdone."; - } + const QString toLocation(QString::fromLatin1("%1/%2/%3").arg(targetDir, info.name, script)); + copyWithException(scriptFile.fileName(), toLocation, QLatin1String("script")); } - // copy user interfaces - const QDomNodeList uiNodes = package.firstChildElement(QLatin1String("UserInterfaces")).childNodes(); - QStringList userinterfaces; - for (int i = 0; i < uiNodes.count(); ++i) { - const QDomNode node = uiNodes.at(i); - if (node.nodeName() != QLatin1String("UserInterface")) - continue; - - const QDir dir(QString::fromLatin1("%1/meta").arg(it->directory)); - const QStringList uis = dir.entryList(QStringList(node.toElement().text()), QDir::Files); - if (uis.isEmpty()) { - throw QInstaller::Error(QString::fromLatin1("Couldn't find any user interface matching '%1' while " - "copying user interfaces of '%2'.").arg(node.toElement().text(), it->name)); - } - - for (QStringList::const_iterator ui = uis.begin(); ui != uis.end(); ++ui) { - qDebug() << "\tCopying associated user interface" << *ui << "into the meta package..."; - userinterfaces.push_back(*ui); - if (!QFile::copy(QString::fromLatin1("%1/meta/%2").arg(it->directory, *ui), - QString::fromLatin1("%1/%2/%3").arg(metapath, it->name, *ui))) { - qDebug() << "failed!"; - throw QInstaller::Error(QString::fromLatin1("Could not copy the UI file '%1' to its target " - "location '%2'.").arg(*ui, it->name)); - } else { - qDebug() << "done"; + // write DownloadableArchives tag if that is missed by the user + if (!foundDownloadableArchives && !info.copiedFiles.isEmpty()) { + QStringList realContentFiles; + foreach (const QString &filePath, info.copiedFiles) { + if (!filePath.endsWith(QLatin1String(".sha1"), Qt::CaseInsensitive)) { + const QString fileName = QFileInfo(filePath).fileName(); + // remove unnecessary version string from filename and add it to the list + realContentFiles.append(fileName.mid(info.version.count())); } } + + update.appendChild(doc.createElement(QLatin1String("DownloadableArchives"))).appendChild(doc + .createTextNode(realContentFiles.join(QChar::fromLatin1(',')))); } - if (!userinterfaces.isEmpty()) { - update.appendChild(doc.createElement(QLatin1String("UserInterfaces"))) - .appendChild(doc.createTextNode(userinterfaces.join(QChar::fromLatin1(',')))); + // copy user interfaces + const QStringList uiFiles = copyFilesFromNode(QLatin1String("UserInterfaces"), + QLatin1String("UserInterface"), QString(), QLatin1String("user interface"), package, info, + targetDir); + if (!uiFiles.isEmpty()) { + update.appendChild(doc.createElement(QLatin1String("UserInterfaces"))).appendChild(doc + .createTextNode(uiFiles.join(QChar::fromLatin1(',')))); } // copy translations - const QDomNodeList qmNodes = package.firstChildElement(QLatin1String("Translations")).childNodes(); - QStringList translations; + QStringList trFiles; if (!qApp->arguments().contains(QString::fromLatin1("--ignore-translations"))) { - for (int i = 0; i < qmNodes.count(); ++i) { - const QDomNode node = qmNodes.at(i); - if (node.nodeName() != QLatin1String("Translation")) - continue; - - const QDir dir(QString::fromLatin1("%1/meta").arg(it->directory)); - const QStringList qms = dir.entryList(QStringList(node.toElement().text()), QDir::Files); - if (qms.isEmpty()) { - throw QInstaller::Error(QString::fromLatin1("Could not find any translation file matching '%1' " - "while copying translations of '%2'.").arg(node.toElement().text(), it->name)); - } - - for (QStringList::const_iterator qm = qms.begin(); qm != qms.end(); ++qm) { - qDebug() << "\tCopying associated translation" << *qm << "into the meta package..."; - translations.push_back(*qm); - if (!QFile::copy(QString::fromLatin1("%1/meta/%2").arg(it->directory, *qm), - QString::fromLatin1("%1/%2/%3").arg(metapath, it->name, *qm))) { - qDebug() << "failed!"; - throw QInstaller::Error(QString::fromLatin1("Could not copy the translation '%1' to its " - "target location '%2'.").arg(*qm, it->name)); - } else { - qDebug() << "done"; - } - } + trFiles = copyFilesFromNode(QLatin1String("Translations"), QLatin1String("Translation"), + QString(), QLatin1String("translation"), package, info, targetDir); + if (!trFiles.isEmpty()) { + update.appendChild(doc.createElement(QLatin1String("Translations"))).appendChild(doc + .createTextNode(trFiles.join(QChar::fromLatin1(',')))); } - - if (!translations.isEmpty()) { - update.appendChild(doc.createElement(QLatin1String("Translations"))) - .appendChild(doc.createTextNode(translations.join(QChar::fromLatin1(',')))); - } - } // copy license files - const QDomNodeList licenseNodes = package.firstChildElement(QLatin1String("Licenses")).childNodes(); - for (int i = 0; i < licenseNodes.count(); ++i) { - const QDomNode licenseNode = licenseNodes.at(i); - if (licenseNode.nodeName() == QLatin1String("License")) { - const QString &licenseFile = - licenseNode.toElement().attributeNode(QLatin1String("file")).value(); - const QString &sourceFile = - QString::fromLatin1("%1/meta/%2").arg(it->directory).arg(licenseFile); - if (!QFile::exists(sourceFile)) { - throw QInstaller::Error(QString::fromLatin1("Could not find any license matching '%1' while " - "copying license files of '%2'.").arg(licenseFile, it->name)); - } - - qDebug() << "\tCopying associated license file" << licenseFile << "into the meta package..."; - if (!QFile::copy(sourceFile, QString::fromLatin1("%1/%2/%3") - .arg(metapath, it->name, licenseFile))) { - qDebug() << "failed!"; - throw QInstaller::Error(QString::fromLatin1("Could not copy the license file '%1' to its " - "target location '%2'.").arg(licenseFile, it->name)); - } else { - qDebug() << "done."; - } - - // Translated License files - for (int j = 0; j < translations.size(); ++j) { - QFileInfo translationFile(translations.at(j)); - QFileInfo untranslated(licenseFile); - const QString &translatedLicenseFile = - QString::fromLatin1("%2_%3.%4").arg(untranslated.baseName(), - translationFile.baseName(), untranslated.completeSuffix()); - const QString &translatedSourceFile = - QString::fromLatin1("%1/meta/%2").arg(it->directory).arg(translatedLicenseFile); - if (!QFile::exists(translatedSourceFile)) { - qDebug() << "Could not find translated license file" << translatedSourceFile; - continue; - } - - qDebug() << "\tCopying associated license file" << translatedLicenseFile - << "into the meta package..."; - - if (!QFile::copy(translatedSourceFile, QString::fromLatin1("%1/%2/%3") - .arg(metapath, it->name, translatedLicenseFile))) { - qDebug() << "\tfailed!"; - } else { - qDebug() << "\tdone."; - } + const QStringList licenses = copyFilesFromNode(QLatin1String("Licenses"), QLatin1String("License"), + QLatin1String("file"), QLatin1String("license"), package, info, targetDir); + if (!licenses.isEmpty()) { + foreach (const QString &trFile, trFiles) { + // Copy translated license file based on the assumption that it will have the same base name + // as the original license plus the file name of an existing translation file without suffix. + foreach (const QString &license, licenses) { + const QFileInfo untranslated(license); + const QString translatedLicense = QString::fromLatin1("%2_%3.%4").arg(untranslated + .baseName(), QFileInfo(trFile).baseName(), untranslated.completeSuffix()); + // ignore copy failure, that's just about the translations + QFile::copy(QString::fromLatin1("%1/meta/%2").arg(info.directory).arg(translatedLicense), + QString::fromLatin1("%1/%2/%3").arg(targetDir, info.name, translatedLicense)); } } - } - - if (licenseNodes.count() > 0) update.appendChild(package.firstChildElement(QLatin1String("Licenses")).cloneNode()); + } } - doc.appendChild(root); - const QString updatesXmlFile = QFileInfo(metapath, QLatin1String("Updates.xml")).absoluteFilePath(); - QFile updatesXml(updatesXmlFile); - - QInstaller::openForWrite(&updatesXml, updatesXmlFile); - QInstaller::blockingWrite(&updatesXml, doc.toByteArray()); + QFile targetUpdatesXml(targetDir + QLatin1String("/Updates.xml")); + QInstaller::openForWrite(&targetUpdatesXml, targetUpdatesXml.fileName()); + QInstaller::blockingWrite(&targetUpdatesXml, doc.toByteArray()); } PackageInfoVector QInstallerTools::createListOfPackages(const QString &packagesDirectory, - const QStringList &filteredPackages, FilterType filterType) + QStringList *packagesToFilter, FilterType filterType) { - qDebug() << "Collecting information about available packages..."; + qDebug() << "\nCollecting information about available packages..."; bool ignoreInvalidPackages = qApp->arguments().contains(QString::fromLatin1("--ignore-invalid-packages")); PackageInfoVector dict; - const QFileInfoList entries = QDir(packagesDirectory) - .entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + const QFileInfoList entries = QDir(packagesDirectory).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); for (QFileInfoList::const_iterator it = entries.begin(); it != entries.end(); ++it) { if (filterType == Exclude) { - if (filteredPackages.contains(it->fileName())) + // Check for current file in exclude list, if found, skip it and remove it from exclude list + if (packagesToFilter->contains(it->fileName())) { + packagesToFilter->removeAll(it->fileName()); continue; + } } else { - if (!filteredPackages.contains(it->fileName())) + // Check for current file in include list, if not found, skip it; if found, remove it from include list + if (!packagesToFilter->contains(it->fileName())) continue; + packagesToFilter->removeAll(it->fileName()); } - qDebug() << QString::fromLatin1("\tfound subdirectory '%1'").arg(it->fileName()); + qDebug() << QString::fromLatin1("found subdirectory '%1'").arg(it->fileName()); // because the filter is QDir::Dirs - filename means the name of the subdirectory if (it->fileName().contains(QLatin1Char('-'))) { if (ignoreInvalidPackages) continue; - throw QInstaller::Error(QString::fromLatin1("Component '%1' mustn't contain '-'. This is not allowed, because " - "dashes are used as the separator between the component name and the version number internally.") - .arg(it->fileName())); + throw QInstaller::Error(QString::fromLatin1("Component '%1' mustn't contain '-'. This is not " + "allowed, because dashes are used as the separator between the component name and the " + "version number internally.").arg(it->fileName())); } QFile file(QString::fromLatin1("%1/meta/package.xml").arg(it->filePath())); @@ -509,11 +462,16 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QString &packagesD .arg(fileInfo.absoluteFilePath(), info.version)); } info.dependencies = packageElement.firstChildElement(QLatin1String("Dependencies")).text() - .split(QInstaller::scCommaRegExp, QString::SkipEmptyParts); + .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); info.directory = it->filePath(); dict.push_back(info); - qDebug() << QString::fromLatin1("\t- it provides the package %1 - %2").arg(name, info.version); + qDebug() << QString::fromLatin1("- it provides the package %1 - %2").arg(info.name, info.version); + } + + if (!packagesToFilter->isEmpty() && packagesToFilter->at(0) != QString::fromLatin1( + "X_fake_filter_component_for_online_only_installer_X")) { + qWarning() << "The following explicitly given packages could not be found\n in package directory:" << *packagesToFilter; } if (dict.isEmpty()) @@ -582,8 +540,10 @@ void QInstallerTools::compressMetaDirectories(const QString &repoDir, const QStr const QByteArray sha1Sum = QInstaller::calculateHash(&tmp, QCryptographicHash::Sha1); writeSHA1ToNodeWithName(doc, elements, sha1Sum, path); const QString finalTarget = absPath + QLatin1String("/") + fn; - if (!tmp.rename(finalTarget)) - throw QInstaller::Error(QString::fromLatin1("Could not move '%1' to '%2'").arg(tmpTarget, finalTarget)); + if (!tmp.rename(finalTarget)) { + throw QInstaller::Error(QString::fromLatin1("Could not move '%1' to '%2'").arg(tmpTarget, + finalTarget)); + } } QInstaller::openForWrite(&existingUpdatesXml, existingUpdatesXml.fileName()); @@ -592,10 +552,10 @@ void QInstallerTools::compressMetaDirectories(const QString &repoDir, const QStr } void QInstallerTools::copyComponentData(const QString &packageDir, const QString &repoDir, - PackageInfoVector &infos) + PackageInfoVector *const infos) { - for (int i = 0; i < infos.count(); ++i) { - const PackageInfo info = infos.at(i); + for (int i = 0; i < infos->count(); ++i) { + const PackageInfo info = infos->at(i); const QString name = info.name; qDebug() << "Copying component data for" << name; @@ -618,8 +578,8 @@ void QInstallerTools::copyComponentData(const QString &packageDir, const QString qDebug() << QString::fromLatin1("Copying archive from '%1' to '%2'").arg(tmp.fileName(), target); if (!tmp.copy(target)) { - throw QInstaller::Error(QString::fromLatin1("Could not copy '%1' to '%2': %3").arg(tmp.fileName(), - target, tmp.errorString())); + throw QInstaller::Error(QString::fromLatin1("Could not copy '%1' to '%2': %3") + .arg(tmp.fileName(), target, tmp.errorString())); } compressedFiles.append(target); } else { @@ -644,7 +604,7 @@ void QInstallerTools::copyComponentData(const QString &packageDir, const QString } foreach (const QString &target, compressedFiles) { - infos[i].copiedArchives.append(target); + (*infos)[i].copiedFiles.append(target); QFile archiveFile(target); QFile archiveHashFile(archiveFile.fileName() + QLatin1String(".sha1")); @@ -661,7 +621,7 @@ void QInstallerTools::copyComponentData(const QString &packageDir, const QString QInstaller::openForWrite(&archiveHashFile, archiveHashFile.fileName()); archiveHashFile.write(hashOfArchiveData); qDebug() << "Generated sha1 hash:" << hashOfArchiveData; - infos[i].copiedArchives.append(archiveHashFile.fileName()); + (*infos)[i].copiedFiles.append(archiveHashFile.fileName()); archiveHashFile.close(); } catch (const QInstaller::Error &/*e*/) { archiveFile.close(); |