Skip to content

Commit

Permalink
Only use filesystem commands for files that exist
Browse files Browse the repository at this point in the history
refs #29141
  • Loading branch information
loganharbour committed Nov 27, 2024
1 parent 6af9dde commit 0f81631
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
15 changes: 6 additions & 9 deletions framework/src/base/Registry.C
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ Registry::addDataFilePath(const std::string & name, const std::string & in_tree_
{
// Enforce that the folder is called "data", because we rely on the installed path
// to be within PREFIX/share/<name>/data (see determineDataFilePath())
const auto abs_in_tree_path = MooseUtils::absolutePath(in_tree_path);
const std::string folder = std::filesystem::path(abs_in_tree_path).filename();
const auto folder = MooseUtils::basename(in_tree_path);
if (folder != "data")
mooseError("While registering data file path '",
abs_in_tree_path,
Expand Down Expand Up @@ -180,21 +179,19 @@ Registry::determineDataFilePath(const std::string & name, const std::string & in
// Installed data
const auto installed_path =
MooseUtils::pathjoin(Moose::getExecutablePath(), "..", "share", name, "data");
const auto abs_installed_path = MooseUtils::absolutePath(installed_path);
if (MooseUtils::checkFileReadable(abs_installed_path, false, false, false))
return installed_path;
return MooseUtils::absolutePath(installed_path);

// In tree data
const auto abs_in_tree_path = MooseUtils::absolutePath(in_tree_path);
if (MooseUtils::checkFileReadable(abs_in_tree_path, false, false, false))
return abs_in_tree_path;
if (MooseUtils::checkFileReadable(in_tree_path, false, false, false))
return MooseUtils::absolutePath(in_tree_path);

mooseError("Failed to determine data file path for '",
name,
"'. Paths searched:\n\n installed: ",
abs_installed_path,
MooseUtils::absolutePath(installed_path),
"\n in-tree: ",
abs_in_tree_path);
MooseUtils::absolutePath(in_tree_path));
}

std::string
Expand Down
9 changes: 4 additions & 5 deletions framework/src/interfaces/DataFileInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ DataFileInterface::getDataFileName(const std::string & param) const

// Look relative to the input file
const auto base = _parent.parameters().getParamFileBase(param);
const auto relative_to_context = MooseUtils::absolutePath(base / value_path);
const auto relative_to_context = base / value_path;
if (MooseUtils::checkFileReadable(relative_to_context, false, false, false))
{
_parent.paramInfo(param, "Data file '", value, "' found relative to the input file.");
return relative_to_context;
return MooseUtils::absolutePath(relative_to_context);
}

// Isn't absolute and couldn't find relative to the input file, so search the data
Expand All @@ -55,9 +55,8 @@ DataFileInterface::getDataFileNameByName(const std::string & relative_path,
for (const auto & [name, path] : Registry::getRegistry().getDataFilePaths())
{
const auto file_path = MooseUtils::pathjoin(path, relative_path);
const std::string abs_file_path = MooseUtils::absolutePath(file_path);
if (MooseUtils::checkFileReadable(abs_file_path, false, false, false))
found.emplace(name, abs_file_path);
if (MooseUtils::checkFileReadable(file_path, false, false, false))
found.emplace(name, MooseUtils::absolutePath(file_path));
else
not_found.emplace(name, path);
}
Expand Down

0 comments on commit 0f81631

Please sign in to comment.