From 3d90ab9345ea1379fa3aea2a26f8eaa498f3e3d0 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 18 May 2021 16:38:55 -0500 Subject: [PATCH] Fix extra slash in canonPath output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When you have a symlink like: /tmp -> ./private/tmp you need to resolve ./private/tmp relative to /tmp’s dir: ‘/’. Unlike any other path output by dirOf, / ends with a slash. We don’t want trailing slashes here since we will append another slash in the next comoponent, so clear s like we would if it was a symlink to an absoute path. This should fix at least part of the issue in https://github.com/NixOS/nix/issues/4822, will need confirmation that it actually fixes the problem to close though. Introduced in f3f228700a52857fe6e8632df4e935551ea219ff. --- src/libutil/util.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 5f597bf06..7e57fd7ca 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -155,6 +155,9 @@ Path canonPath(const Path & path, bool resolveSymlinks) s.clear(); /* restart for symlinks pointing to absolute path */ } else { s = dirOf(s); + if (s == "/") { // we don’t want trailing slashes here, which dirOf only produces if s = / + s.clear(); + } } } }