use search paths; unit tests still pass. RB #5763. opens the way for device specific files, for instance, so a plasmoid will be able to have different qml files for different targets (where that makes sense).
svn path=/trunk/KDE/kdelibs/; revision=1192748
This commit is contained in:
parent
433bb098dd
commit
95a18aca96
59
package.cpp
59
package.cpp
@ -163,7 +163,15 @@ bool Package::isValid() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (const char *dir, d->structure->requiredDirectories()) {
|
foreach (const char *dir, d->structure->requiredDirectories()) {
|
||||||
if (!QFile::exists(d->structure->path() + d->structure->contentsPrefix() + d->structure->path(dir))) {
|
bool failed = true;
|
||||||
|
foreach (const QString &path, d->structure->searchPath(dir)) {
|
||||||
|
if (QFile::exists(d->structure->path() + d->structure->contentsPrefix() + path)) {
|
||||||
|
failed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
kWarning() << "Could not find required directory" << dir;
|
kWarning() << "Could not find required directory" << dir;
|
||||||
d->valid = false;
|
d->valid = false;
|
||||||
return false;
|
return false;
|
||||||
@ -171,9 +179,16 @@ bool Package::isValid() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (const char *file, d->structure->requiredFiles()) {
|
foreach (const char *file, d->structure->requiredFiles()) {
|
||||||
if (!QFile::exists(d->structure->path() + d->structure->contentsPrefix() + d->structure->path(file))) {
|
bool failed = true;
|
||||||
kWarning() << "Could not find required file" << file << ", look in"
|
foreach (const QString &path, d->structure->searchPath(file)) {
|
||||||
<< d->structure->path() + d->structure->contentsPrefix() + d->structure->path(file) << endl;
|
if (QFile::exists(d->structure->path() + d->structure->contentsPrefix() + path)) {
|
||||||
|
failed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
|
kWarning() << "Could not find required file" << file;
|
||||||
d->valid = false;
|
d->valid = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -189,34 +204,38 @@ QString Package::filePath(const char *fileType, const QString &filename) const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path;
|
QStringList paths;
|
||||||
|
|
||||||
if (qstrlen(fileType) != 0) {
|
if (qstrlen(fileType) != 0) {
|
||||||
path = d->structure->path(fileType);
|
paths = d->structure->searchPath(fileType);
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (paths.isEmpty()) {
|
||||||
//kDebug() << "no matching path came of it, while looking for" << fileType << filename;
|
//kDebug() << "no matching path came of it, while looking for" << fileType << filename;
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path.prepend(d->structure->path() + d->structure->contentsPrefix());
|
const QString prefix(d->structure->path() + d->structure->contentsPrefix());
|
||||||
|
|
||||||
if (!filename.isEmpty()) {
|
foreach (const QString &path, paths) {
|
||||||
path.append("/").append(filename);
|
QString file = prefix + path;
|
||||||
}
|
|
||||||
|
|
||||||
if (QFile::exists(path)) {
|
if (!filename.isEmpty()) {
|
||||||
if (d->structure->allowExternalPaths()) {
|
file.append("/").append(filename);
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that we don't return files outside of our base path
|
if (QFile::exists(file)) {
|
||||||
// due to symlink or ../ games
|
if (d->structure->allowExternalPaths()) {
|
||||||
QDir dir(path);
|
return file;
|
||||||
QString canonicalized = dir.canonicalPath() + QDir::separator();
|
}
|
||||||
if (canonicalized.startsWith(d->structure->path())) {
|
|
||||||
return path;
|
// ensure that we don't return files outside of our base path
|
||||||
|
// due to symlink or ../ games
|
||||||
|
QDir dir(file);
|
||||||
|
QString canonicalized = dir.canonicalPath() + QDir::separator();
|
||||||
|
if (canonicalized.startsWith(d->structure->path())) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user