simplify using platform function
This commit is contained in:
@ -1016,28 +1016,13 @@ bool utils::is_id(const std::string &str)
|
|||||||
|
|
||||||
std::string utils::get_potential_file_path(const std::string &path)
|
std::string utils::get_potential_file_path(const std::string &path)
|
||||||
{
|
{
|
||||||
std::string filepath = path;
|
if (platform::file_is_readable(path)) {
|
||||||
std::string filename = platform::path_basename(path);
|
return path;
|
||||||
|
|
||||||
if (platform::file_is_readable(filepath)) {
|
|
||||||
return filepath;
|
|
||||||
} else {
|
} else {
|
||||||
// try the environment variable directory
|
for (const auto &dir : platform::list_pathenv("LAMMPS_POTENTIALS")) {
|
||||||
const char *var = getenv("LAMMPS_POTENTIALS");
|
auto pot = platform::path_basename(path);
|
||||||
|
auto filepath = platform::path_join(dir, pot);
|
||||||
if (var != nullptr) {
|
if (platform::file_is_readable(filepath)) return filepath;
|
||||||
#if defined(_WIN32)
|
|
||||||
Tokenizer dirs(var, ";");
|
|
||||||
#else
|
|
||||||
Tokenizer dirs(var, ":");
|
|
||||||
#endif
|
|
||||||
while (dirs.has_next()) {
|
|
||||||
auto pot = platform::path_basename(filepath);
|
|
||||||
auto dir = dirs.next();
|
|
||||||
filepath = platform::path_join(dir, pot);
|
|
||||||
|
|
||||||
if (platform::file_is_readable(filepath)) { return filepath; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
Reference in New Issue
Block a user