Catch exception thrown when checking if a path is a symlink

MSVC's implementation of std::filesystem::is_symlink throws if
given a perfectly valid path, saying
"symlink_status: The parameter is incorrect."

This appears to be a bug in the implementation, though I can't
reproduce it.
This commit is contained in:
Oliver Hamlet
2019-01-26 20:24:58 +00:00
parent fd29783e41
commit 07afb0e64a
+16 -2
View File
@@ -35,8 +35,22 @@ namespace fs = std::filesystem;
namespace loot {
std::filesystem::path ResolvePath(const std::filesystem::path& path) {
if (fs::is_symlink(path))
return fs::read_symlink(path);
// is_symlink can throw on MSVC with the message
// "symlink_status: The parameter is incorrect."
// even though a perfectly valid (non-symlink) path is given. This has been
// seen with a non C: drive path, but not reproduced, so just catch the
// exception and log it.
try {
if (fs::is_symlink(path))
return fs::read_symlink(path);
} catch (std::exception& e) {
auto logger = getLogger();
if (logger) {
logger->error("Could not check or read potential symlink path \"{}\": {}",
path.u8string(),
e.what());
}
}
return path;
}