aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-api.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r--src/libstore/store-api.cc89
1 files changed, 42 insertions, 47 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index aae227bae..e4a4ae11e 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -61,7 +61,7 @@ StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view p
/* Store paths have the following form:
- <store>/<h>-<name>
+ <realized-path> = <store>/<h>-<name>
where
@@ -85,11 +85,14 @@ StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view p
<type> = one of:
"text:<r1>:<r2>:...<rN>"
for plain text files written to the store using
- addTextToStore(); <r1> ... <rN> are the references of the
- path.
- "source"
+ addTextToStore(); <r1> ... <rN> are the store paths referenced
+ by this path, in the form described by <realized-path>
+ "source:<r1>:<r2>:...:<rN>:self"
for paths copied to the store using addToStore() when recursive
- = true and hashAlgo = "sha256"
+ = true and hashAlgo = "sha256". Just like in the text case, we
+ can have the store paths referenced by the path.
+ Additionally, we can have an optional :self label to denote self
+ reference.
"output:<id>"
for either the outputs created by derivations, OR paths copied
to the store using addToStore() with recursive != true or
@@ -117,6 +120,12 @@ StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view p
the contents of the path (or expected contents of the
path for fixed-output derivations)
+ Note that since an output derivation has always type output, while
+ something added by addToStore can have type output or source depending
+ on the hash, this means that the same input can be hashed differently
+ if added to the store via addToStore or via a derivation, in the sha256
+ recursive case.
+
It would have been nicer to handle fixed-output derivations under
"source", e.g. have something like "source:<rec><algo>", but we're
stuck with this for now...
@@ -164,20 +173,20 @@ static std::string makeType(
StorePath Store::makeFixedOutputPath(
- FileIngestionMethod recursive,
+ FileIngestionMethod method,
const Hash & hash,
std::string_view name,
const StorePathSet & references,
bool hasSelfReference) const
{
- if (hash.type == htSHA256 && recursive == FileIngestionMethod::Recursive) {
+ if (hash.type == htSHA256 && method == FileIngestionMethod::Recursive) {
return makeStorePath(makeType(*this, "source", references, hasSelfReference), hash, name);
} else {
assert(references.empty());
return makeStorePath("output:out",
hashString(htSHA256,
"fixed:out:"
- + (recursive == FileIngestionMethod::Recursive ? (string) "r:" : "")
+ + makeFileIngestionPrefix(method)
+ hash.to_string(Base16, true) + ":"),
name);
}
@@ -462,8 +471,8 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & store
jsonRefs.elem(printStorePath(ref));
}
- if (info->ca != "")
- jsonPath.attr("ca", info->ca);
+ if (info->ca)
+ jsonPath.attr("ca", renderContentAddress(info->ca));
std::pair<uint64_t, uint64_t> closureSizes;
@@ -748,41 +757,35 @@ void ValidPathInfo::sign(const Store & store, const SecretKey & secretKey)
sigs.insert(secretKey.signDetached(fingerprint(store)));
}
+// FIXME Put this somewhere?
+template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
+template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
bool ValidPathInfo::isContentAddressed(const Store & store) const
{
- auto warn = [&]() {
- logWarning(
- ErrorInfo{
- .name = "Path not content-addressed",
- .hint = hintfmt("path '%s' claims to be content-addressed but isn't", store.printStorePath(path))
- });
- };
-
- if (hasPrefix(ca, "text:")) {
- Hash hash(ca.substr(5));
- if (store.makeTextPath(path.name(), hash, references) == path)
- return true;
- else
- warn();
- }
+ if (! ca) return false;
- else if (hasPrefix(ca, "fixed:")) {
- FileIngestionMethod recursive { ca.compare(6, 2, "r:") == 0 };
- Hash hash(ca.substr(recursive == FileIngestionMethod::Recursive ? 8 : 6));
- auto refs = references;
- bool hasSelfReference = false;
- if (refs.count(path)) {
- hasSelfReference = true;
- refs.erase(path);
+ auto caPath = std::visit(overloaded {
+ [&](TextHash th) {
+ return store.makeTextPath(path.name(), th.hash, references);
+ },
+ [&](FixedOutputHash fsh) {
+ auto refs = references;
+ bool hasSelfReference = false;
+ if (refs.count(path)) {
+ hasSelfReference = true;
+ refs.erase(path);
+ }
+ return store.makeFixedOutputPath(fsh.method, fsh.hash, path.name(), refs, hasSelfReference);
}
- if (store.makeFixedOutputPath(recursive, hash, path.name(), refs, hasSelfReference) == path)
- return true;
- else
- warn();
- }
+ }, *ca);
+
+ bool res = caPath == path;
- return false;
+ if (!res)
+ printError("warning: path '%s' claims to be content-addressed but isn't", store.printStorePath(path));
+
+ return res;
}
@@ -813,14 +816,6 @@ Strings ValidPathInfo::shortRefs() const
}
-std::string makeFixedOutputCA(FileIngestionMethod recursive, const Hash & hash)
-{
- return "fixed:"
- + (recursive == FileIngestionMethod::Recursive ? (std::string) "r:" : "")
- + hash.to_string(Base32, true);
-}
-
-
}