mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Add SourceAccessor::getFingerprint()
This returns the fingerprint for a specific subpath. This is intended for "composite" accessors like MountedSourceAccessor, where different subdirectories can have different fingerprints.
This commit is contained in:
parent
55c7ef9d40
commit
28d11c5bcc
5 changed files with 50 additions and 0 deletions
|
|
@ -60,6 +60,13 @@ std::string FilteringSourceAccessor::showPath(const CanonPath & path)
|
||||||
return displayPrefix + next->showPath(prefix / path) + displaySuffix;
|
return displayPrefix + next->showPath(prefix / path) + displaySuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<CanonPath, std::optional<std::string>> FilteringSourceAccessor::getFingerprint(const CanonPath & path)
|
||||||
|
{
|
||||||
|
if (fingerprint)
|
||||||
|
return {path, fingerprint};
|
||||||
|
return next->getFingerprint(prefix / path);
|
||||||
|
}
|
||||||
|
|
||||||
void FilteringSourceAccessor::checkAccess(const CanonPath & path)
|
void FilteringSourceAccessor::checkAccess(const CanonPath & path)
|
||||||
{
|
{
|
||||||
if (!isAllowed(path))
|
if (!isAllowed(path))
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ struct FilteringSourceAccessor : SourceAccessor
|
||||||
|
|
||||||
std::string showPath(const CanonPath & path) override;
|
std::string showPath(const CanonPath & path) override;
|
||||||
|
|
||||||
|
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call `makeNotAllowedError` to throw a `RestrictedPathError`
|
* Call `makeNotAllowedError` to throw a `RestrictedPathError`
|
||||||
* exception if `isAllowed()` returns `false` for `path`.
|
* exception if `isAllowed()` returns `false` for `path`.
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,27 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
||||||
*/
|
*/
|
||||||
std::optional<std::string> fingerprint;
|
std::optional<std::string> fingerprint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the fingerprint for `path`. This is usually the
|
||||||
|
* fingerprint of the current accessor, but for composite
|
||||||
|
* accessors (like `MountedSourceAccessor`), we want to return the
|
||||||
|
* fingerprint of the "inner" accessor if the current one lacks a
|
||||||
|
* fingerprint.
|
||||||
|
*
|
||||||
|
* So this method is intended to return the most-outer accessor
|
||||||
|
* that has a fingerprint for `path`. It also returns the path that `path`
|
||||||
|
* corresponds to in that accessor.
|
||||||
|
*
|
||||||
|
* For example: in a `MountedSourceAccessor` that has
|
||||||
|
* `/nix/store/foo` mounted,
|
||||||
|
* `getFingerprint("/nix/store/foo/bar")` will return the path
|
||||||
|
* `/bar` and the fingerprint of the `/nix/store/foo` accessor.
|
||||||
|
*/
|
||||||
|
virtual std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path)
|
||||||
|
{
|
||||||
|
return {path, fingerprint};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the maximum last-modified time of the files in this
|
* Return the maximum last-modified time of the files in this
|
||||||
* tree, if available.
|
* tree, if available.
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,14 @@ struct MountedSourceAccessorImpl : MountedSourceAccessor
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override
|
||||||
|
{
|
||||||
|
if (fingerprint)
|
||||||
|
return {path, fingerprint};
|
||||||
|
auto [accessor, subpath] = resolve(path);
|
||||||
|
return accessor->getFingerprint(subpath);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ref<MountedSourceAccessor> makeMountedSourceAccessor(std::map<CanonPath, ref<SourceAccessor>> mounts)
|
ref<MountedSourceAccessor> makeMountedSourceAccessor(std::map<CanonPath, ref<SourceAccessor>> mounts)
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,18 @@ struct UnionSourceAccessor : SourceAccessor
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override
|
||||||
|
{
|
||||||
|
if (fingerprint)
|
||||||
|
return {path, fingerprint};
|
||||||
|
for (auto & accessor : accessors) {
|
||||||
|
auto [subpath, fingerprint] = accessor->getFingerprint(path);
|
||||||
|
if (fingerprint)
|
||||||
|
return {subpath, fingerprint};
|
||||||
|
}
|
||||||
|
return {path, std::nullopt};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ref<SourceAccessor> makeUnionSourceAccessor(std::vector<ref<SourceAccessor>> && accessors)
|
ref<SourceAccessor> makeUnionSourceAccessor(std::vector<ref<SourceAccessor>> && accessors)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue