From d73831e8f00764e120a892f29f8da3ae39a95c48 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 21 Sep 2009 21:48:19 +0000 Subject: [PATCH] * hash() -> contentsHash() * add the metadata file to the hash as well * update test svn path=/trunk/KDE/kdelibs/; revision=1026497 --- package.cpp | 20 +++++++++++++++++--- package.h | 2 +- tests/plasmoidpackagetest.cpp | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package.cpp b/package.cpp index ba08b0732..8551cf04e 100644 --- a/package.cpp +++ b/package.cpp @@ -202,8 +202,8 @@ void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, hash.update(f.read(1024)); } } else { - kWarning() << "permissions fail?" << info.permissions() << info.isFile(); - kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading"; + kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading. " + << "permissions fail?" << info.permissions() << info.isFile(); } } } @@ -224,7 +224,7 @@ void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, } #endif -QString Package::hash() const +QString Package::contentsHash() const { #ifdef QCA2_FOUND if (!QCA::isSupported("sha1")) { @@ -240,6 +240,20 @@ QString Package::hash() const } QCA::Hash hash("sha1"); + QString metadataPath = d->structure->path() + "metadata.desktop"; + if (QFile::exists(metadataPath)) { + QFile f(metadataPath); + if (f.open(QIODevice::ReadOnly)) { + while (!f.atEnd()) { + hash.update(f.read(1024)); + } + } else { + kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading."; + } + } else { + kWarning() << "no metadata at" << metadataPath; + } + d->updateHash(basePath, QString(), dir, hash); return QCA::arrayToHex(hash.final().toByteArray()); #else diff --git a/package.h b/package.h index e785c9cca..2ec8e686d 100644 --- a/package.h +++ b/package.h @@ -138,7 +138,7 @@ class PLASMA_EXPORT Package /** * @return a SHA1 hash digest of the contents of the package in hexadecimal form */ - QString hash() const; + QString contentsHash() const; /** * Returns a list of all installed packages by name diff --git a/tests/plasmoidpackagetest.cpp b/tests/plasmoidpackagetest.cpp index 3131d0d88..3f09d33f5 100644 --- a/tests/plasmoidpackagetest.cpp +++ b/tests/plasmoidpackagetest.cpp @@ -183,7 +183,7 @@ void PlasmoidPackageTest::isValid() p = new Plasma::Package(mPackageRoot, mPackage, ps); QVERIFY(p->isValid()); #ifdef QCA2_FOUND - QCOMPARE(QString("0b8c7de4bee1ac6f373276ac2b5776c9194b2c56"), p->hash()); + QCOMPARE(p->contentsHash(), QString("db0b38c2b4fe21a9f37923cc25152340de055f6d")); #endif }