From 38aeba4936ad4b462cfd8a7769f367b2dbb8ec1f Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Fri, 26 May 2017 19:09:04 +0300 Subject: Fix adding SHA1 node Searching existing sha1sum node and keep/replace/add it if needed. These changes correct the adding of two SHA1 nodes when the packages are repackaged (option --repository via repogen and binarycreator) Change-Id: Ide99946644fd73fadc63f23d34d7aec16b0399a2 Reviewed-by: Katja Marttila --- tools/common/repositorygen.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'tools/common') diff --git a/tools/common/repositorygen.cpp b/tools/common/repositorygen.cpp index 2942728c2..1c4a877c0 100644 --- a/tools/common/repositorygen.cpp +++ b/tools/common/repositorygen.cpp @@ -50,6 +50,7 @@ #include +using namespace QInstaller; using namespace QInstallerTools; void QInstallerTools::printRepositoryGenOptions() @@ -624,13 +625,28 @@ QHash QInstallerTools::buildPathToVersionMapping(const Package static void writeSHA1ToNodeWithName(QDomDocument &doc, QDomNodeList &list, const QByteArray &sha1sum, const QString &nodename) { - qDebug() << "searching sha1sum node for" << nodename; + qDebug() << "Searching sha1sum node for" << nodename; + QString sha1Value = QString::fromLatin1(sha1sum.toHex().constData()); for (int i = 0; i < list.size(); ++i) { QDomNode curNode = list.at(i); - QDomNode nameTag = curNode.firstChildElement(QLatin1String("Name")); + QDomNode nameTag = curNode.firstChildElement(scName); if (!nameTag.isNull() && nameTag.toElement().text() == nodename) { - QDomNode sha1Node = doc.createElement(QLatin1String("SHA1")); - sha1Node.appendChild(doc.createTextNode(QString::fromLatin1(sha1sum.toHex().constData()))); + QDomNode sha1Node = curNode.firstChildElement(scSHA1); + if (!sha1Node.isNull() && sha1Node.hasChildNodes()) { + QDomNode sha1NodeChild = sha1Node.firstChild(); + QString sha1OldValue = sha1NodeChild.nodeValue(); + if (sha1Value == sha1OldValue) { + qDebug() << "- keeping the existing sha1sum" << sha1OldValue; + continue; + } else { + qDebug() << "- clearing the old sha1sum" << sha1OldValue; + sha1Node.removeChild(sha1NodeChild); + } + } else { + sha1Node = doc.createElement(scSHA1); + } + qDebug() << "- writing the sha1sum" << sha1Value; + sha1Node.appendChild(doc.createTextNode(sha1Value)); curNode.appendChild(sha1Node); } } -- cgit v1.2.3