* hash() -> contentsHash()

* add the metadata file to the hash as well
* update test

svn path=/trunk/KDE/kdelibs/; revision=1026497
This commit is contained in:
Aaron J. Seigo 2009-09-21 21:48:19 +00:00
parent 19f55f804b
commit d73831e8f0
3 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}