summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2018-05-09 13:05:45 +0300
committerKatja Marttila <katja.marttila@qt.io>2018-06-01 05:06:48 +0000
commit85bff5f7b8c5958277f3b763ec6dba4bd8ec94c4 (patch)
tree6162468a6cbb334fc29b97dc5371d2a59068fe0d /src/libs
parentd5be955bbb6cf595f7f6c30c4b1904c153a4d7c7 (diff)
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 <iikka.eklund@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/installer/metadatajob.cpp38
-rw-r--r--src/libs/kdtools/filedownloader.cpp13
-rw-r--r--src/libs/kdtools/filedownloader.h1
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 <QTemporaryDir>
#include <QtMath>
+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<FileTaskResult> &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<FileTaskResult> &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;