summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Podsvirov <konstantin@podsvirov.pro>2016-06-21 13:56:22 +0300
committerKonstantin Podsvirov <konstantin@podsvirov.pro>2016-07-07 05:19:34 +0000
commit80e8809b0b6a68100409ce664670ae493693b629 (patch)
tree20a68e18cd4c063dac2fa1a459f5e8fe7d9814e9
parent810ea81009c594edb5f80110297e2562ca3c2b43 (diff)
Resolve relative URLs from Updates.xml
This change allows you to use relative URLs to update repositories. Absolute addresses are resolved relative to the current Updates.xml file is parsed. Documentation added to ifw-updates.html page. Change-Id: I5935355dfeee2236e9752cc2545c2d42da216f9e Reviewed-by: Konstantin Podsvirov <konstantin@podsvirov.pro> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r--doc/installerfw.qdoc41
-rw-r--r--src/libs/installer/metadatajob.cpp16
2 files changed, 51 insertions, 6 deletions
diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc
index 7a667f912..af1089d1f 100644
--- a/doc/installerfw.qdoc
+++ b/doc/installerfw.qdoc
@@ -1256,6 +1256,14 @@
displayname="Example Repository" />
\endcode
+ \c{url} will be used as a base url to resolve an \c{Updates.xml} file against.
+ If \c{url} is itself relative, it will be resolved against the base url of the current document.
+
+ \c{displayname} specifies how the repository should be named in the \gui Settings page
+ of the Maintenance Tool.
+
+ \c{name} and \c{password} optionally specify credentials for a protected repository.
+
\section2 Removing Repositories
To remove a repository, add a \c <Repository> child element to the
\c <RepositoryUpdate> element with the following options:
@@ -1264,15 +1272,44 @@
<Repository action="remove" url="http://www.example.com/repository" />
\endcode
+ \c{url} must match exactly the url that is to be removed.
+
\section2 Replacing Repositories
To replace one repository with another, add a \c <Repository> child element to the
\c <RepositoryUpdate> element with the following options:
\code
- <Repository action="replace" oldurl="http://www.example.com/repository"
- newurl="http://www.example.com/newrepository" name="user" password="password"
+ <Repository action="replace" oldUrl="http://www.example.com/repository"
+ newUrl="http://www.example.com/newrepository" name="user" password="password"
displayname="New Example Repository" />
\endcode
+
+ \c{oldUrl} must match exactly the url that is to be replaced.
+
+ \c{newUrl} must match exactly the url that is replace to.
+
+ \section1 Relocatable Repositories
+
+ Some projects contain multiple repositories. To create relocatable set
+ of repositories you should use relative paths.
+
+ So if generic repository available at address \c{http://www.example.com/repositories/generic}
+ and \c{Updates.xml} contains \c <Repository> element with the following options:
+
+ \code
+ <Repository action="add" url="../module" name="user" password="password"
+ displayname="Module Repository" />
+ \endcode
+
+ Resolved address of added repository will be \c{http://www.example.com/repositories/module}.
+ So that the repository does not contain information about their absolute location.
+
+ If you want to change the address, you can simply copy a set of repositories as is.
+ It recommended for some time to maintain the old generic repository and replace addresses
+ as described above. You can also provide the updated installer with the new generic address.
+
+ You can use relative path for arguments \c url, \c oldUrl and \c newUrl at
+ \c <Repository> element.
*/
/*!
diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp
index 5186df409..58b1ede8e 100644
--- a/src/libs/installer/metadatajob.cpp
+++ b/src/libs/installer/metadatajob.cpp
@@ -44,6 +44,14 @@
namespace QInstaller {
+static QUrl resolveUrl(const FileTaskResult &result, const QString &url)
+{
+ QUrl u(url);
+ if (u.isRelative())
+ return QUrl(result.taskItem().source()).resolved(u);
+ return u;
+}
+
MetadataJob::MetadataJob(QObject *parent)
: Job(parent)
, m_core(0)
@@ -379,7 +387,7 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList<FileTaskResult> &re
const QString action = el.attribute(QLatin1String("action"));
if (action == QLatin1String("add")) {
// add a new repository to the defaults list
- Repository repository(el.attribute(QLatin1String("url")), true);
+ Repository repository(resolveUrl(result, el.attribute(QLatin1String("url"))), true);
repository.setUsername(el.attribute(QLatin1String("username")));
repository.setPassword(el.attribute(QLatin1String("password")));
repository.setDisplayName(el.attribute(QLatin1String("displayname")));
@@ -389,14 +397,14 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList<FileTaskResult> &re
}
} else if (action == QLatin1String("remove")) {
// remove possible default repositories using the given server url
- Repository repository(el.attribute(QLatin1String("url")), true);
+ Repository repository(resolveUrl(result, el.attribute(QLatin1String("url"))), true);
repositoryUpdates.insertMulti(action, qMakePair(repository, Repository()));
qDebug() << "Repository to remove:" << repository.displayname();
} else if (action == QLatin1String("replace")) {
// replace possible default repositories using the given server url
- Repository oldRepository(el.attribute(QLatin1String("oldUrl")), true);
- Repository newRepository(el.attribute(QLatin1String("newUrl")), true);
+ Repository oldRepository(resolveUrl(result, el.attribute(QLatin1String("oldUrl"))), true);
+ Repository newRepository(resolveUrl(result, el.attribute(QLatin1String("newUrl"))), true);
newRepository.setUsername(el.attribute(QLatin1String("username")));
newRepository.setPassword(el.attribute(QLatin1String("password")));
newRepository.setDisplayName(el.attribute(QLatin1String("displayname")));