Get the data path for a given path, searching the registered data.
27 std::optional<std::string> data_name;
29 if (std::regex_search(path, match, std::regex(
"(?:(\\w+):)?(.*)")))
34 if (!data_paths.count(*data_name))
35 mooseError(
"Data from '", *data_name,
"' is not registered to be searched");
40 mooseError(
"Failed to parse path '", path,
"'");
42 const std::filesystem::path value_path = std::filesystem::path(path);
45 if (std::filesystem::path(path).is_absolute())
48 mooseError(
"Should not specify an absolute path along with a data name to search (requested " 54 mooseError(
"The absolute path '", path,
"' does not exist or is not readable.");
58 std::map<std::string, std::string> not_found;
70 std::optional<std::string> skip_data_reason;
72 if (path.size() > 1 && path.substr(0, 2) ==
"./")
74 skip_data_reason =
"begins with './'";
79 const std::string proximate = std::filesystem::proximate(path).c_str();
80 if (proximate.size() > 1 && proximate.substr(0, 2) ==
"..")
82 skip_data_reason =
"resolves behind '.'";
87 std::map<std::string, std::string> found;
88 if (!skip_data_reason)
89 for (
const auto & [name, data_path] : data_paths)
92 if (data_name && name != *data_name)
98 not_found.emplace(name +
" data", data_path);
102 if (found.size() == 1)
104 const auto & [
name, data_path] = *found.begin();
108 std::stringstream oss;
110 if (found.size() > 1)
112 oss <<
"Multiple files were found when searching for the data file '" << path <<
"':\n\n";
113 for (
const auto & [name, data_path] : found)
114 oss <<
" " <<
name <<
": " << data_path <<
"\n";
115 const auto & first_name = found.begin()->first;
116 oss <<
"\nYou can resolve this ambiguity by appending a prefix with the desired data name, for " 118 << first_name <<
":" << path;
123 oss <<
"Unable to find the data file '" << path <<
"' anywhere.\n";
124 if (not_found.size())
126 oss <<
"\nPaths searched:\n";
127 for (
const auto & [name, data_path] : not_found)
128 oss <<
" " <<
name <<
": " << data_path <<
"\n";
130 if (skip_data_reason)
131 oss <<
"\nData path(s) were not searched because search path " << *skip_data_reason <<
".\n";
std::string name(const ElemQuality q)
static Registry & getRegistry()
Get the global Registry singleton.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
std::string canonicalPath(const std::string &path)
Gets the canonical path of the given path.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
std::filesystem::path pathjoin(const std::filesystem::path &p)
static const std::map< std::string, std::string > & getDataFilePaths()
Returns a map of all registered data file paths (name -> path)