forked from lix-project/lix
Get rid of confusing std::optional<bool>
for validity
This commit is contained in:
parent
c4bf219b55
commit
6387550d58
1 changed files with 23 additions and 12 deletions
|
@ -718,16 +718,25 @@ typedef enum {rpAccept, rpDecline, rpPostpone} HookReply;
|
||||||
|
|
||||||
class SubstitutionGoal;
|
class SubstitutionGoal;
|
||||||
|
|
||||||
|
/* Unless we are repairing, we don't both to test validity and just assume it,
|
||||||
|
so the choices are `Absent` or `Valid`. */
|
||||||
|
enum struct PathStatus {
|
||||||
|
Corrupt,
|
||||||
|
Absent,
|
||||||
|
Valid,
|
||||||
|
};
|
||||||
|
|
||||||
struct InitialOutputStatus {
|
struct InitialOutputStatus {
|
||||||
StorePath path;
|
StorePath path;
|
||||||
/* The output optional indicates whether it's already valid; i.e. exists
|
PathStatus status;
|
||||||
and is registered. If we're repairing, inner bool indicates whether the
|
|
||||||
valid path is in fact not corrupt. Otherwise, the inner bool is always
|
|
||||||
true (assumed no corruption). */
|
|
||||||
std::optional<bool> valid;
|
|
||||||
/* Valid in the store, and additionally non-corrupt if we are repairing */
|
/* Valid in the store, and additionally non-corrupt if we are repairing */
|
||||||
bool isValid() const {
|
bool isValid() const {
|
||||||
return valid && *valid;
|
return status == PathStatus::Valid;
|
||||||
|
}
|
||||||
|
/* Merely present, allowed to be corrupt */
|
||||||
|
bool isPresent() const {
|
||||||
|
return status == PathStatus::Corrupt
|
||||||
|
|| status == PathStatus::Valid;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2148,10 +2157,10 @@ void DerivationGoal::startBuilder()
|
||||||
: !needsHashRewrite()
|
: !needsHashRewrite()
|
||||||
/* Can always use original path in sandbox */
|
/* Can always use original path in sandbox */
|
||||||
? status.known->path
|
? status.known->path
|
||||||
: !status.known->valid
|
: !status.known->isPresent()
|
||||||
/* If path doesn't yet exist can just use it */
|
/* If path doesn't yet exist can just use it */
|
||||||
? status.known->path
|
? status.known->path
|
||||||
: buildMode != bmRepair && !*status.known->valid
|
: buildMode != bmRepair && !status.known->isValid()
|
||||||
/* If we aren't repairing we'll delete a corrupted path, so we
|
/* If we aren't repairing we'll delete a corrupted path, so we
|
||||||
can use original path */
|
can use original path */
|
||||||
? status.known->path
|
? status.known->path
|
||||||
|
@ -2161,7 +2170,7 @@ void DerivationGoal::startBuilder()
|
||||||
scratchOutputs.insert_or_assign(outputName, scratchPath);
|
scratchOutputs.insert_or_assign(outputName, scratchPath);
|
||||||
|
|
||||||
/* A non-removed corrupted path needs to be stored here, too */
|
/* A non-removed corrupted path needs to be stored here, too */
|
||||||
if (buildMode == bmRepair && !*status.known->valid)
|
if (buildMode == bmRepair && !status.known->isValid())
|
||||||
redirectedBadOutputs.insert(status.known->path);
|
redirectedBadOutputs.insert(status.known->path);
|
||||||
|
|
||||||
/* Substitute output placeholders with the scratch output paths.
|
/* Substitute output placeholders with the scratch output paths.
|
||||||
|
@ -4596,9 +4605,11 @@ void DerivationGoal::checkPathValidity()
|
||||||
auto outputPath = *i.second;
|
auto outputPath = *i.second;
|
||||||
info.known = {
|
info.known = {
|
||||||
.path = outputPath,
|
.path = outputPath,
|
||||||
.valid = !worker.store.isValidPath(outputPath)
|
.status = !worker.store.isValidPath(outputPath)
|
||||||
? std::optional<bool> {}
|
? PathStatus::Absent
|
||||||
: !checkHash || worker.pathContentsGood(outputPath),
|
: !checkHash || worker.pathContentsGood(outputPath)
|
||||||
|
? PathStatus::Valid
|
||||||
|
: PathStatus::Corrupt,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
initialOutputs.insert_or_assign(i.first, info);
|
initialOutputs.insert_or_assign(i.first, info);
|
||||||
|
|
Loading…
Reference in a new issue