From f97489e7ab0fe4c47201ec142a20de8b2caab924 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Jul 2022 15:24:41 +0200 Subject: [PATCH] Remove parent hackery from the path fetcher Relative paths of subflakes are now handled in lockFlake(). --- src/libexpr/flake/flakeref.cc | 5 +---- src/libfetchers/fetchers.hh | 3 --- src/libfetchers/path.cc | 18 +----------------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 162656087..0b30b8467 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -204,11 +204,8 @@ std::pair parseFlakeRefWithFragment( std::string fragment; std::swap(fragment, parsedURL.fragment); - auto input = Input::fromURL(parsedURL); - input.parent = baseDir; - return std::make_pair( - FlakeRef(std::move(input), getOr(parsedURL.query, "dir", "")), + FlakeRef(Input::fromURL(parsedURL), getOr(parsedURL.query, "dir", "")), fragment); } } diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index ccba68dc9..e6792d81d 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -37,9 +37,6 @@ struct Input bool locked = false; bool direct = true; - /* path of the parent of this input, used for relative path resolution */ - std::optional parent; - public: static Input fromURL(const std::string & url); diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 1236ecf7e..ff95fad7d 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -93,23 +93,7 @@ struct PathInputScheme : InputScheme if (path[0] == '/') return CanonPath(path); - // FIXME: remove this? - if (!input.parent) - throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string()); - - CanonPath parent(*input.parent); - - // the path isn't relative, prefix it - auto absPath = CanonPath(path, parent); - - // for security, ensure that if the parent is a store path, it's inside it - if (store->isInStore(parent.abs())) { - auto storePath = store->printStorePath(store->toStorePath(parent.abs()).first); - if (!absPath.isWithin(CanonPath(storePath))) - throw BadStorePath("relative path '%s' points outside of its parent's store path '%s'", path, storePath); - } - - return absPath; + throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string()); } std::pair fetch(ref store, const Input & _input) override