mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
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:
+16
-2
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user