aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/primops.cc9
-rw-r--r--src/libstore/build.cc10
-rw-r--r--src/libstore/path.hh2
-rw-r--r--src/libstore/store-api.cc21
4 files changed, 28 insertions, 14 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 71a511c41..4d5aaf86a 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -724,9 +724,12 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
auto outPath = state.store->makeFixedOutputPath(outputHashRecursive, h, drvName);
if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath);
- drv.outputs.insert_or_assign("out", DerivationOutput(std::move(outPath),
- (static_cast<bool>(outputHashRecursive) ? "r:" : "") + printHashType(h.type),
- h.to_string(Base16, false)));
+ drv.outputs.insert_or_assign("out", DerivationOutput {
+ std::move(outPath),
+ (outputHashRecursive == FileIngestionMethod::Recursive ? "r:" : "")
+ + printHashType(h.type),
+ h.to_string(Base16, false),
+ });
}
else {
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 224633106..be52e637e 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -3650,7 +3650,7 @@ void DerivationGoal::registerOutputs()
FileIngestionMethod recursive; Hash h;
i.second.parseHashInfo(recursive, h);
- if (!static_cast<bool>(recursive)) {
+ if (recursive == FileIngestionMethod::Flat) {
/* The output path should be a regular file without execute permission. */
if (!S_ISREG(st.st_mode) || (st.st_mode & S_IXUSR) != 0)
throw BuildError(
@@ -3659,7 +3659,9 @@ void DerivationGoal::registerOutputs()
/* Check the hash. In hash mode, move the path produced by
the derivation to its content-addressed location. */
- Hash h2 = static_cast<bool>(recursive) ? hashPath(h.type, actualPath).first : hashFile(h.type, actualPath);
+ Hash h2 = recursive == FileIngestionMethod::Recursive
+ ? hashPath(h.type, actualPath).first
+ : hashFile(h.type, actualPath);
auto dest = worker.store.makeFixedOutputPath(recursive, h2, i.second.path.name());
@@ -3912,7 +3914,9 @@ void DerivationGoal::checkOutputs(const std::map<Path, ValidPathInfo> & outputs)
auto spec = parseReferenceSpecifiers(worker.store, *drv, *value);
- auto used = static_cast<bool>(recursive) ? cloneStorePathSet(getClosure(info.path).first) : cloneStorePathSet(info.references);
+ auto used = recursive
+ ? cloneStorePathSet(getClosure(info.path).first)
+ : cloneStorePathSet(info.references);
if (recursive && checks.ignoreSelfRefs)
used.erase(info.path);
diff --git a/src/libstore/path.hh b/src/libstore/path.hh
index 73c4b8e29..5122e7422 100644
--- a/src/libstore/path.hh
+++ b/src/libstore/path.hh
@@ -73,7 +73,7 @@ const size_t storePathHashLen = 32; // i.e. 160 bits
/* Extension of derivations in the Nix store. */
const std::string drvExtension = ".drv";
-enum struct FileIngestionMethod : bool {
+enum struct FileIngestionMethod : uint8_t {
Flat = false,
Recursive = true
};
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 06aa0883c..ca1409588 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -177,13 +177,16 @@ StorePath Store::makeFixedOutputPath(
const StorePathSet & references,
bool hasSelfReference) const
{
- if (hash.type == htSHA256 && recursive == FileIngestionMethod::Recursive) {
+ if (hash.type == htSHA256 && recursive == FileIngestionMethod::Recursive) {
return makeStorePath(makeType(*this, "source", references, hasSelfReference), hash, name);
} else {
assert(references.empty());
- return makeStorePath("output:out", hashString(htSHA256,
- "fixed:out:" + (static_cast<bool>(recursive) ? (string) "r:" : "") +
- hash.to_string(Base16) + ":"), name);
+ return makeStorePath("output:out",
+ hashString(htSHA256,
+ "fixed:out:"
+ + (recursive == FileIngestionMethod::Recursive ? (string) "r:" : "")
+ + hash.to_string(Base16) + ":"),
+ name);
}
}
@@ -202,7 +205,9 @@ StorePath Store::makeTextPath(std::string_view name, const Hash & hash,
std::pair<StorePath, Hash> Store::computeStorePathForPath(std::string_view name,
const Path & srcPath, FileIngestionMethod recursive, HashType hashAlgo, PathFilter & filter) const
{
- Hash h = static_cast<bool>(recursive) ? hashPath(hashAlgo, srcPath, filter).first : hashFile(hashAlgo, srcPath);
+ Hash h = recursive == FileIngestionMethod::Recursive
+ ? hashPath(hashAlgo, srcPath, filter).first
+ : hashFile(hashAlgo, srcPath);
return std::make_pair(makeFixedOutputPath(recursive, h, name), h);
}
@@ -782,7 +787,7 @@ bool ValidPathInfo::isContentAddressed(const Store & store) const
else if (hasPrefix(ca, "fixed:")) {
FileIngestionMethod recursive { ca.compare(6, 2, "r:") == 0 };
- Hash hash(std::string(ca, static_cast<bool>(recursive) ? 8 : 6));
+ Hash hash(std::string(ca, recursive == FileIngestionMethod::Recursive ? 8 : 6));
auto refs = cloneStorePathSet(references);
bool hasSelfReference = false;
if (refs.count(path)) {
@@ -828,7 +833,9 @@ Strings ValidPathInfo::shortRefs() const
std::string makeFixedOutputCA(FileIngestionMethod recursive, const Hash & hash)
{
- return "fixed:" + (static_cast<bool>(recursive) ? (std::string) "r:" : "") + hash.to_string();
+ return "fixed:"
+ + (recursive == FileIngestionMethod::Recursive ? (std::string) "r:" : "")
+ + hash.to_string();
}