From 85bff5f7b8c5958277f3b763ec6dba4bd8ec94c4 Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Wed, 9 May 2018 13:05:45 +0300 Subject: Decrease metadata dowload amount If there are no Script, Translations, Licenses nor UserInterfaces -tags in Updates.xml, there is no metadata. In such case, do not download the empty metadata to decrease the time used in downloading metadata. Task-number: QTIFW-975 Change-Id: I1b81a07b5ad43677e190fb058ece8b06382d215b Reviewed-by: Iikka Eklund --- src/libs/installer/metadatajob.cpp | 38 +++++++++++++++++++++++++------------ src/libs/kdtools/filedownloader.cpp | 13 +++++++++++++ src/libs/kdtools/filedownloader.h | 1 + 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp index bd577fecf..f56eb43a3 100644 --- a/src/libs/installer/metadatajob.cpp +++ b/src/libs/installer/metadatajob.cpp @@ -39,6 +39,8 @@ #include #include +const QStringList metaElements = {QLatin1String("Script"), QLatin1String("Licenses"), QLatin1String("UserInterfaces"), QLatin1String("Translations")}; + namespace QInstaller { static QUrl resolveUrl(const FileTaskResult &result, const QString &url) @@ -534,6 +536,7 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList &re if (!el.isNull() && el.tagName() == QLatin1String("PackageUpdate")) { const QDomNodeList c2 = el.childNodes(); QString packageName, packageVersion, packageHash; + bool metaFound = false; for (int j = 0; j < c2.count(); ++j) { if (c2.at(j).toElement().tagName() == scName) packageName = c2.at(j).toElement().text(); @@ -541,21 +544,32 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList &re packageVersion = (online ? c2.at(j).toElement().text() : QString()); else if ((c2.at(j).toElement().tagName() == QLatin1String("SHA1")) && testCheckSum) packageHash = c2.at(j).toElement().text(); + else { + foreach (QString meta, metaElements) { + if (c2.at(j).toElement().tagName() == meta) { + metaFound = true; + break; + } + } + } } const QString repoUrl = metadata.repository.url().toString(); - FileTaskItem item(QString::fromLatin1("%1/%2/%3meta.7z").arg(repoUrl, packageName, - packageVersion), metadata.directory + QString::fromLatin1("/%1-%2-meta.7z") - .arg(packageName, packageVersion)); - - QAuthenticator authenticator; - authenticator.setUser(metadata.repository.username()); - authenticator.setPassword(metadata.repository.password()); - - item.insert(TaskRole::UserRole, metadata.directory); - item.insert(TaskRole::Checksum, packageHash.toLatin1()); - item.insert(TaskRole::Authenticator, QVariant::fromValue(authenticator)); - m_packages.append(item); + //If script element is not found, no need to fetch metadata + if (metaFound) { + FileTaskItem item(QString::fromLatin1("%1/%2/%3meta.7z").arg(repoUrl, packageName, + packageVersion), metadata.directory + QString::fromLatin1("/%1-%2-meta.7z") + .arg(packageName, packageVersion)); + + QAuthenticator authenticator; + authenticator.setUser(metadata.repository.username()); + authenticator.setPassword(metadata.repository.password()); + + item.insert(TaskRole::UserRole, metadata.directory); + item.insert(TaskRole::Checksum, packageHash.toLatin1()); + item.insert(TaskRole::Authenticator, QVariant::fromValue(authenticator)); + m_packages.append(item); + } } } m_metadata.insert(metadata.directory, metadata); diff --git a/src/libs/kdtools/filedownloader.cpp b/src/libs/kdtools/filedownloader.cpp index 8032bbe22..5574a3af6 100644 --- a/src/libs/kdtools/filedownloader.cpp +++ b/src/libs/kdtools/filedownloader.cpp @@ -660,6 +660,17 @@ void KDUpdater::FileDownloader::resetCheckSumData() d->m_hash.reset(); } +/*! + Creates a directory structure for \a fileName if it does not exist. +*/ +void KDUpdater::FileDownloader::createDirectoryForFile(const QString fileName) +{ + QFileInfo fileInfo(fileName); + if (!fileInfo.absoluteDir().exists()) { + QDir filePath = fileInfo.absoluteDir(); + filePath.mkdir(filePath.absolutePath()); + } +} /*! Returns a copy of the proxy factory that this FileDownloader object is using to determine the @@ -814,6 +825,7 @@ void KDUpdater::LocalFileDownloader::doDownload() file->open(); d->destination = file; } else { + createDirectoryForFile(d->destFileName); d->destination = new QFile(d->destFileName, this); d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate); } @@ -1466,6 +1478,7 @@ void KDUpdater::HttpDownloader::startDownload(const QUrl &url) file->open(); d->destination = file; } else { + createDirectoryForFile(d->destFileName); d->destination = new QFile(d->destFileName, this); d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate); } diff --git a/src/libs/kdtools/filedownloader.h b/src/libs/kdtools/filedownloader.h index ede20dcfa..10a041fba 100644 --- a/src/libs/kdtools/filedownloader.h +++ b/src/libs/kdtools/filedownloader.h @@ -140,6 +140,7 @@ protected: void addCheckSumData(const QByteArray &data); void addCheckSumData(const char *data, int length); void resetCheckSumData(); + void createDirectoryForFile(const QString fileName); private Q_SLOTS: virtual void doDownload() = 0; -- cgit v1.2.3