mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Use isAbsolute()
This commit is contained in:
parent
ff8e2fe84e
commit
ff9d886f3c
7 changed files with 12 additions and 12 deletions
|
@ -406,7 +406,7 @@ void EvalState::checkURI(const std::string & uri)
|
||||||
|
|
||||||
/* If the URI is a path, then check it against allowedPaths as
|
/* If the URI is a path, then check it against allowedPaths as
|
||||||
well. */
|
well. */
|
||||||
if (hasPrefix(uri, "/")) {
|
if (isAbsolute(uri)) {
|
||||||
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
|
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
|
||||||
rootFS2->checkAccess(CanonPath(uri));
|
rootFS2->checkAccess(CanonPath(uri));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -97,7 +97,7 @@ struct PathInputScheme : InputScheme
|
||||||
std::optional<std::string> isRelative(const Input & input) const
|
std::optional<std::string> isRelative(const Input & input) const
|
||||||
{
|
{
|
||||||
auto path = getStrAttr(input.attrs, "path");
|
auto path = getStrAttr(input.attrs, "path");
|
||||||
if (hasPrefix(path, "/"))
|
if (isAbsolute(path))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
else
|
else
|
||||||
return path;
|
return path;
|
||||||
|
|
|
@ -153,7 +153,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, re
|
||||||
return std::make_shared<Registry>(settings, Registry::Global); // empty registry
|
return std::make_shared<Registry>(settings, Registry::Global); // empty registry
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasPrefix(path, "/")) {
|
if (!isAbsolute(path)) {
|
||||||
auto storePath = downloadFile(store, path, "flake-registry.json").storePath;
|
auto storePath = downloadFile(store, path, "flake-registry.json").storePath;
|
||||||
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
||||||
store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json");
|
store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json");
|
||||||
|
|
|
@ -178,7 +178,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!hasPrefix(path, "/"))
|
if (!isAbsolute(path))
|
||||||
throw BadURL("flake reference '%s' is not an absolute path", url);
|
throw BadURL("flake reference '%s' is not an absolute path", url);
|
||||||
path = canonPath(path + "/" + getOr(query, "dir", ""));
|
path = canonPath(path + "/" + getOr(query, "dir", ""));
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
|
||||||
auto parsed = parseURL(url);
|
auto parsed = parseURL(url);
|
||||||
if (baseDir
|
if (baseDir
|
||||||
&& (parsed.scheme == "path" || parsed.scheme == "git+file")
|
&& (parsed.scheme == "path" || parsed.scheme == "git+file")
|
||||||
&& !hasPrefix(parsed.path, "/"))
|
&& !isAbsolute(parsed.path))
|
||||||
parsed.path = absPath(parsed.path, *baseDir);
|
parsed.path = absPath(parsed.path, *baseDir);
|
||||||
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
|
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
|
||||||
} catch (BadURL &) {
|
} catch (BadURL &) {
|
||||||
|
|
|
@ -31,12 +31,7 @@ namespace nix {
|
||||||
|
|
||||||
namespace fs { using namespace std::filesystem; }
|
namespace fs { using namespace std::filesystem; }
|
||||||
|
|
||||||
/**
|
bool isAbsolute(PathView path)
|
||||||
* Treat the string as possibly an absolute path, by inspecting the
|
|
||||||
* start of it. Return whether it was probably intended to be
|
|
||||||
* absolute.
|
|
||||||
*/
|
|
||||||
static bool isAbsolute(PathView path)
|
|
||||||
{
|
{
|
||||||
return fs::path { path }.is_absolute();
|
return fs::path { path }.is_absolute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,11 @@ namespace nix {
|
||||||
struct Sink;
|
struct Sink;
|
||||||
struct Source;
|
struct Source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the path denotes an absolute path.
|
||||||
|
*/
|
||||||
|
bool isAbsolute(PathView path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return An absolutized path, resolving paths relative to the
|
* @return An absolutized path, resolving paths relative to the
|
||||||
* specified directory, or the current directory otherwise. The path
|
* specified directory, or the current directory otherwise. The path
|
||||||
|
|
|
@ -115,7 +115,7 @@ CanonPath SourceAccessor::resolveSymlinks(
|
||||||
throw Error("infinite symlink recursion in path '%s'", showPath(path));
|
throw Error("infinite symlink recursion in path '%s'", showPath(path));
|
||||||
auto target = readLink(res);
|
auto target = readLink(res);
|
||||||
res.pop();
|
res.pop();
|
||||||
if (hasPrefix(target, "/"))
|
if (isAbsolute(target))
|
||||||
res = CanonPath::root;
|
res = CanonPath::root;
|
||||||
todo.splice(todo.begin(), tokenizeString<std::list<std::string>>(target, "/"));
|
todo.splice(todo.begin(), tokenizeString<std::list<std::string>>(target, "/"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue