diff --git a/src/libfetchers/mounted-input-accessor.cc b/src/libfetchers/mounted-input-accessor.cc index 49917f6e5..6f397eb17 100644 --- a/src/libfetchers/mounted-input-accessor.cc +++ b/src/libfetchers/mounted-input-accessor.cc @@ -54,18 +54,16 @@ struct MountedInputAccessor : InputAccessor std::pair, CanonPath> resolve(CanonPath path) { // Find the nearest parent of `path` that is a mount point. - std::vector ss; + std::vector subpath; while (true) { auto i = mounts.find(path); if (i != mounts.end()) { - auto subpath = CanonPath::root; - for (auto j = ss.rbegin(); j != ss.rend(); ++j) - subpath.push(*j); - return {i->second, std::move(subpath)}; + std::reverse(subpath.begin(), subpath.end()); + return {i->second, CanonPath(subpath)}; } assert(!path.isRoot()); - ss.push_back(std::string(*path.baseName())); + subpath.push_back(std::string(*path.baseName())); path.pop(); } } diff --git a/src/libutil/canon-path.cc b/src/libutil/canon-path.cc index f678fae94..1e465f1f6 100644 --- a/src/libutil/canon-path.cc +++ b/src/libutil/canon-path.cc @@ -13,6 +13,13 @@ CanonPath::CanonPath(std::string_view raw, const CanonPath & root) : path(absPath((Path) raw, root.abs())) { } +CanonPath::CanonPath(const std::vector & elems) + : path("/") +{ + for (auto & s : elems) + push(s); +} + CanonPath CanonPath::fromCwd(std::string_view path) { return CanonPath(unchecked_t(), absPath((Path) path)); diff --git a/src/libutil/canon-path.hh b/src/libutil/canon-path.hh index eefe05ed5..6d0519f4f 100644 --- a/src/libutil/canon-path.hh +++ b/src/libutil/canon-path.hh @@ -6,6 +6,7 @@ #include #include #include +#include namespace nix { @@ -46,6 +47,11 @@ public: : path(std::move(path)) { } + /** + * Construct a canon path from a vector of elements. + */ + CanonPath(const std::vector & elems); + static CanonPath fromCwd(std::string_view path = "."); static CanonPath root;