Remove parent hackery from the path fetcher

Relative paths of subflakes are now handled in lockFlake().
This commit is contained in:
Eelco Dolstra 2022-07-22 15:24:41 +02:00
parent 3d27ce36d0
commit f97489e7ab
3 changed files with 2 additions and 24 deletions

View file

@ -204,11 +204,8 @@ std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
std::string fragment; std::string fragment;
std::swap(fragment, parsedURL.fragment); std::swap(fragment, parsedURL.fragment);
auto input = Input::fromURL(parsedURL);
input.parent = baseDir;
return std::make_pair( return std::make_pair(
FlakeRef(std::move(input), getOr(parsedURL.query, "dir", "")), FlakeRef(Input::fromURL(parsedURL), getOr(parsedURL.query, "dir", "")),
fragment); fragment);
} }
} }

View file

@ -37,9 +37,6 @@ struct Input
bool locked = false; bool locked = false;
bool direct = true; bool direct = true;
/* path of the parent of this input, used for relative path resolution */
std::optional<Path> parent;
public: public:
static Input fromURL(const std::string & url); static Input fromURL(const std::string & url);

View file

@ -93,23 +93,7 @@ struct PathInputScheme : InputScheme
if (path[0] == '/') if (path[0] == '/')
return CanonPath(path); return CanonPath(path);
// FIXME: remove this? throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
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;
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override