From 122b384d601062fc46f653a69561908b1e2d45a0 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 7 Oct 2019 12:20:12 +0200 Subject: [PATCH] logic: fix FilePath::makeCanonical for case when working directory is symlink on Windows (issue #733) This was broken because on first iteration loop the path passed to is_symlink was not a real path, thus boost uses the working dir instead. --- src/lib/utility/file/FilePath.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index b1398a13..38564ea1 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -158,7 +158,14 @@ FilePath& FilePath::makeCanonical() #if defined(_WIN32) boost::filesystem::path abs_p = boost::filesystem::absolute(getPath()); - for (boost::filesystem::path::iterator it = abs_p.begin(); it != abs_p.end(); ++it) + + boost::filesystem::path::iterator it = abs_p.begin(); + + // add first element before loop because this won't be recognized as absolute path yet + canonicalPath /= *it; + it++; + + for (; it != abs_p.end(); ++it) { if (*it == "..") { @@ -172,7 +179,7 @@ FilePath& FilePath::makeCanonical() { canonicalPath /= *it; - if (boost::filesystem::is_symlink(canonicalPath)) + if (boost::filesystem::is_symlink(boost::filesystem::symlink_status(canonicalPath))) { boost::filesystem::path symlink = boost::filesystem::read_symlink(canonicalPath); if (!symlink.empty())