treat no prefixes as the same as one prefix starting at the package root. probably not a bottleneck, but the duplicated code indicates that this may be better placed in PackageStructure in future. this is the path (excuse the pun :) of least change, however.

svn path=/trunk/KDE/kdelibs/; revision=1206637
This commit is contained in:
Aaron J. Seigo 2010-12-15 06:29:36 +00:00
parent e2ea3a5715
commit b6edd5beca

View File

@ -158,17 +158,22 @@ Package &Package::operator=(const Package &rhs)
bool Package::isValid() const bool Package::isValid() const
{ {
if (!d->valid || d->structure->contentsPrefixPaths().isEmpty()) { if (!d->valid) {
return false; return false;
} }
//search for the file in all prefixes and in all possible paths for each prefix //search for the file in all prefixes and in all possible paths for each prefix
//even if it's a big nested loop, usually there is one prefix and one location //even if it's a big nested loop, usually there is one prefix and one location
//so shouldn't cause too much disk access //so shouldn't cause too much disk access
QStringList prefixes = d->structure->contentsPrefixPaths();
if (prefixes.isEmpty()) {
prefixes << QString();
}
foreach (const char *dir, d->structure->requiredDirectories()) { foreach (const char *dir, d->structure->requiredDirectories()) {
bool failed = true; bool failed = true;
foreach (const QString &path, d->structure->searchPath(dir)) { foreach (const QString &path, d->structure->searchPath(dir)) {
foreach (const QString &prefix, d->structure->contentsPrefixPaths()) { foreach (const QString &prefix, prefixes) {
if (QFile::exists(d->structure->path() + prefix + path)) { if (QFile::exists(d->structure->path() + prefix + path)) {
failed = false; failed = false;
break; break;
@ -189,7 +194,7 @@ bool Package::isValid() const
foreach (const char *file, d->structure->requiredFiles()) { foreach (const char *file, d->structure->requiredFiles()) {
bool failed = true; bool failed = true;
foreach (const QString &path, d->structure->searchPath(file)) { foreach (const QString &path, d->structure->searchPath(file)) {
foreach (const QString &prefix, d->structure->contentsPrefixPaths()) { foreach (const QString &prefix, prefixes) {
if (QFile::exists(d->structure->path() + prefix + path)) { if (QFile::exists(d->structure->path() + prefix + path)) {
failed = false; failed = false;
break; break;
@ -232,7 +237,12 @@ QString Package::filePath(const char *fileType, const QString &filename) const
} }
//Nested loop, but in the medium case resolves to just one iteration //Nested loop, but in the medium case resolves to just one iteration
foreach (const QString &contentsPrefix, d->structure->contentsPrefixPaths()) { QStringList prefixes = d->structure->contentsPrefixPaths();
if (prefixes.isEmpty()) {
prefixes << QString();
}
foreach (const QString &contentsPrefix, prefixes) {
const QString prefix(d->structure->path() + contentsPrefix); const QString prefix(d->structure->path() + contentsPrefix);
foreach (const QString &path, paths) { foreach (const QString &path, paths) {
@ -386,7 +396,12 @@ QString Package::contentsHash() const
kWarning() << "no metadata at" << metadataPath; kWarning() << "no metadata at" << metadataPath;
} }
foreach (QString prefix, d->structure->contentsPrefixPaths()) { QStringList prefixes = d->structure->contentsPrefixPaths();
if (prefixes.isEmpty()) {
prefixes << QString();
}
foreach (QString prefix, prefixes) {
const QString basePath = d->structure->path() + prefix; const QString basePath = d->structure->path() + prefix;
QDir dir(basePath); QDir dir(basePath);