1 #include "fileutils.h"
2 #include "printutils.h"
3
4 #include <boost/filesystem.hpp>
5 namespace fs = boost::filesystem;
6
7 /*!
8 Returns the absolute path to the given filename, unless it's empty.
9 If the file isn't found in the given path, the fallback path will be
10 used to be backwards compatible with <= 2013.01 (see issue #217).
11 */
lookup_file(const std::string & filename,const std::string & path,const std::string & fallbackpath)12 std::string lookup_file(const std::string &filename,
13 const std::string &path, const std::string &fallbackpath)
14 {
15 std::string resultfile;
16 if (!filename.empty() && !fs::path(filename).is_absolute()) {
17 fs::path absfile;
18 if (!path.empty()) absfile = fs::absolute(fs::path(path) / filename);
19 fs::path absfile_fallback;
20 if (!fallbackpath.empty()) absfile_fallback = fs::absolute(fs::path(fallbackpath) / filename);
21
22 if (!fs::exists(absfile) && fs::exists(absfile_fallback)) {
23 resultfile = absfile_fallback.string();
24 LOG(message_group::Deprecated,Location::NONE,"","Imported file (%1$s) found in document root instead of relative to the importing module. This behavior is deprecated",std::string(filename));
25 }
26 else {
27 resultfile = absfile.string();
28 }
29 }
30 else {
31 resultfile = filename;
32 }
33 return resultfile;
34 }
35