summaryrefslogtreecommitdiff
path: root/src/plugins/filesystem/FileLocator.cpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-29 21:31:41 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-29 21:31:41 +0100
commitea99528bdefdeb6ab0b0b8bc2a87ab52f2b5169c (patch)
treef3a1eb47390df7e6449643c5b8f30514fa1810a5 /src/plugins/filesystem/FileLocator.cpp
parent1a831356eee562451c8ce85654ec3b650658e7f9 (diff)
further attempts on making the main program work. Had to add a method for handling absolute paths in FileLocator for that.
Diffstat (limited to 'src/plugins/filesystem/FileLocator.cpp')
-rw-r--r--src/plugins/filesystem/FileLocator.cpp47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/plugins/filesystem/FileLocator.cpp b/src/plugins/filesystem/FileLocator.cpp
index 356394e..822c9fe 100644
--- a/src/plugins/filesystem/FileLocator.cpp
+++ b/src/plugins/filesystem/FileLocator.cpp
@@ -101,6 +101,11 @@ void FileLocator::addDefaultSearchPaths()
#ifndef NDEBUG
addDefaultSearchPaths(SpecialPaths::getDebugDataDir());
#endif
+ // also add working directory.
+ addSearchPath(".", {ResourceType::UNKNOWN, ResourceType::DOMAIN_DESC,
+ ResourceType::TYPESYSTEM, ResourceType::DOCUMENT,
+ ResourceType::ATTRIBUTES, ResourceType::STYLESHEET,
+ ResourceType::SCRIPT, ResourceType::DATA});
}
void FileLocator::addUnittestSearchPath(const std::string &subdir,
@@ -111,6 +116,20 @@ void FileLocator::addUnittestSearchPath(const std::string &subdir,
type);
}
+static bool checkPath(Resource &resource, const ResourceLocator &locator,
+ fs::path p, const ResourceType type)
+{
+ if (fs::exists(p) && fs::is_regular_file(p)) {
+ std::string location = fs::canonical(p).generic_string();
+#ifdef FILELOCATOR_DEBUG_PRINT
+ std::cout << "FileLocator: Found at " << location << std::endl;
+#endif
+ resource = Resource(true, locator, type, location);
+ return true;
+ }
+ return false;
+}
+
bool FileLocator::doLocate(Resource &resource, const std::string &path,
const ResourceType type,
const std::string &relativeTo) const
@@ -131,13 +150,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path,
base /= path;
// If we already found a fitting resource there, use that.
- if (fs::exists(base) && fs::is_regular_file(base)) {
- std::string location = fs::canonical(base).generic_string();
-#ifdef FILELOCATOR_DEBUG_PRINT
- std::cout << "FileLocator: Found \"" << path << "\" at "
- << location << std::endl;
-#endif
- resource = Resource(true, *this, type, location);
+ if (checkPath(resource, *this, base, type)) {
return true;
}
}
@@ -148,6 +161,18 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path,
return false;
}
+ // If the path is an absolute path, look at this exact point.
+ {
+ fs::path p{path};
+ if (p.is_absolute()) {
+ if (checkPath(resource, *this, p, type)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
// Otherwise look in the search paths, search backwards, last defined search
// paths have a higher precedence
auto it = searchPaths.find(type);
@@ -159,13 +184,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path,
#endif
fs::path p{*it};
p /= path;
- if (fs::exists(p) && fs::is_regular_file(p)) {
- std::string location = fs::canonical(p).generic_string();
-#ifdef FILELOCATOR_DEBUG_PRINT
- std::cout << "FileLocator: Found \"" << path << "\" in "
- << location << std::endl;
-#endif
- resource = Resource(true, *this, type, location);
+ if (checkPath(resource, *this, p, type)) {
return true;
}
}