mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
PathInputSchema::getAbsPath(): Return std::filesystem::path
This commit is contained in:
parent
521667eb89
commit
5d03ef9caf
1 changed files with 7 additions and 7 deletions
|
@ -91,7 +91,7 @@ struct PathInputScheme : InputScheme
|
||||||
std::string_view contents,
|
std::string_view contents,
|
||||||
std::optional<std::string> commitMsg) const override
|
std::optional<std::string> commitMsg) const override
|
||||||
{
|
{
|
||||||
writeFile((CanonPath(getAbsPath(input)) / path).abs(), contents);
|
writeFile(getAbsPath(input) / path.rel(), contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> isRelative(const Input & input) const override
|
std::optional<std::string> isRelative(const Input & input) const override
|
||||||
|
@ -108,12 +108,12 @@ struct PathInputScheme : InputScheme
|
||||||
return (bool) input.getNarHash();
|
return (bool) input.getNarHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
CanonPath getAbsPath(const Input & input) const
|
std::filesystem::path getAbsPath(const Input & input) const
|
||||||
{
|
{
|
||||||
auto path = getStrAttr(input.attrs, "path");
|
auto path = getStrAttr(input.attrs, "path");
|
||||||
|
|
||||||
if (path[0] == '/')
|
if (isAbsolute(path))
|
||||||
return CanonPath(path);
|
return canonPath(path);
|
||||||
|
|
||||||
throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
|
throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ struct PathInputScheme : InputScheme
|
||||||
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying '%s' to the store", absPath));
|
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying '%s' to the store", absPath));
|
||||||
|
|
||||||
// FIXME: check whether access to 'path' is allowed.
|
// FIXME: check whether access to 'path' is allowed.
|
||||||
auto storePath = store->maybeParseStorePath(absPath.abs());
|
auto storePath = store->maybeParseStorePath(absPath.string());
|
||||||
|
|
||||||
if (storePath)
|
if (storePath)
|
||||||
store->addTempRoot(*storePath);
|
store->addTempRoot(*storePath);
|
||||||
|
@ -137,7 +137,7 @@ struct PathInputScheme : InputScheme
|
||||||
if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) {
|
if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) {
|
||||||
// FIXME: try to substitute storePath.
|
// FIXME: try to substitute storePath.
|
||||||
auto src = sinkToSource([&](Sink & sink) {
|
auto src = sinkToSource([&](Sink & sink) {
|
||||||
mtime = dumpPathAndGetMtime(absPath.abs(), sink, defaultPathFilter);
|
mtime = dumpPathAndGetMtime(absPath.string(), sink, defaultPathFilter);
|
||||||
});
|
});
|
||||||
storePath = store->addToStoreFromDump(*src, "source");
|
storePath = store->addToStoreFromDump(*src, "source");
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ struct PathInputScheme : InputScheme
|
||||||
store object and the subpath. */
|
store object and the subpath. */
|
||||||
auto path = getAbsPath(input);
|
auto path = getAbsPath(input);
|
||||||
try {
|
try {
|
||||||
auto [storePath, subPath] = store->toStorePath(path.abs());
|
auto [storePath, subPath] = store->toStorePath(path.string());
|
||||||
auto info = store->queryPathInfo(storePath);
|
auto info = store->queryPathInfo(storePath);
|
||||||
return fmt("path:%s:%s", info->narHash.to_string(HashFormat::Base16, false), subPath);
|
return fmt("path:%s:%s", info->narHash.to_string(HashFormat::Base16, false), subPath);
|
||||||
} catch (Error &) {
|
} catch (Error &) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue