diff options
author | Mykola Orliuk <virkony@gmail.com> | 2021-03-31 04:20:41 +0200 |
---|---|---|
committer | Mykola Orliuk <virkony@gmail.com> | 2021-03-31 04:58:49 +0200 |
commit | f3f228700a52857fe6e8632df4e935551ea219ff (patch) | |
tree | 7a9a5d8b518c10452399aea4690f06673a08c4ea | |
parent | e7810665a72592de08b61b1e83b150b5282e1e82 (diff) |
canonPath in one pass
-rw-r--r-- | src/libutil/util.cc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index dea9c74b7..c092076f3 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -143,16 +143,18 @@ Path canonPath(const Path & path, bool resolveSymlinks) s += '/'; while (i != end && *i != '/') s += *i++; - /* If s points to a symlink, resolve it and restart (since - the symlink target might contain new symlinks). */ + /* If s points to a symlink, resolve it and continue from there */ if (resolveSymlinks && isLink(s)) { if (++followCount >= maxFollow) throw Error("infinite symlink recursion in path '%1%'", path); - temp = absPath(readLink(s), dirOf(s)) - + string(i, end); - i = temp.begin(); /* restart */ + temp = readLink(s) + string(i, end); + i = temp.begin(); end = temp.end(); - s = ""; + if (!temp.empty() && temp[0] == '/') { + s.clear(); /* restart for symlinks pointing to absolute path */ + } else { + s = dirOf(s); + } } } } |