From 07afb0e64a8860107bcf72ea0d59f469de776011 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 26 Jan 2019 18:27:52 +0000 Subject: [PATCH] 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. --- src/api/api.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 5a9384d9..8644a84d 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -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; }