Skip to content

Commit

Permalink
file-system: strip trailing slashes again in canonPath
Browse files Browse the repository at this point in the history
  • Loading branch information
puffnfresh committed Nov 12, 2024
1 parent e16ab7c commit 2c842c7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/libutil/file-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,19 @@ Path canonPath(PathView path, bool resolveSymlinks)
// The standard filesystem library will behave differently. For example,
// libstd++ in GCC will only resolve 40 symlinks.
// I hope that isn't a problem!
return (resolveSymlinks ? fs::canonical(path) : fs::path { path }.lexically_normal()).string();
auto result = resolveSymlinks ? fs::weakly_canonical(path) : fs::path { path }.lexically_normal();

// Strip trailing slashes
while (!result.has_filename() && result.has_parent_path())
{
// The parent of "D:/" is "D:/" so we need to be careful.
fs::path parent = result.parent_path();
if (parent == result)
break;
result = parent;
}

return result.string();
}


Expand Down

0 comments on commit 2c842c7

Please sign in to comment.