diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2013-05-19 20:14:05 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2013-05-19 20:14:05 (GMT) |
commit | 24e726fb58d2eca9e18575ffb76e547f958608de (patch) | |
tree | 18ca1837beb4bfea67c3d5a46f3cc4fee4689165 /src/parsersettings.cc | |
parent | e25fff81af72a31f6118f4840b65193aa0ec1d0a (diff) |
first refactoring towards fixing issue364
Diffstat (limited to 'src/parsersettings.cc')
-rw-r--r-- | src/parsersettings.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 8d82744..4273f7c 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -20,13 +20,50 @@ void add_librarydir(const std::string &libdir) Searces for the given file in library paths and returns the full path if found. Returns an empty path if file cannot be found or filename is a directory. */ -std::string locate_file(const std::string &filename) +fs::path search_libs(const std::string &filename) { BOOST_FOREACH(const std::string &dir, librarypath) { fs::path usepath = fs::path(dir) / filename; if (fs::exists(usepath) && !fs::is_directory(usepath)) return usepath.string(); } - return std::string(); + return fs::path(); +} + +// files must be 'ordinary' - they mus exist and be non-directories +bool check_valid( fs::path p ) +{ + // if p empty PRINT("WARNING: 'use' filename is blank"); + if (!p.has_parent_path()) { + PRINTB("WARNING: %s invalid - no parent path",p); + return false; + } + if (!fs::exists(p)) { + PRINTB("WARNING: %s invalid - file not found",p); + // searched === + return false; + } + if (fs::is_directory(p)) { + PRINTB("WARNING: %s invalid - points to a directory",p); + return false; + } + return true; +} + +// check if file is valid, search path for valid simple file +// return empty path on failure +fs::path find_valid_path( fs::path sourcepath, std::string filename ) +{ + fs::path fpath = fs::path( filename ); + + if ( boosty::is_absolute( fpath ) ) + if ( check_valid( fpath ) ) + return boosty::absolute( fpath ); + + fpath = sourcepath / filename; + if ( check_valid( fpath ) ) return fpath; + fpath = search_libs( filename ); + if ( check_valid( fpath ) ) return fpath; + return fs::path(); } void parser_init(const std::string &applicationpath) |