1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 22:12:43 +01:00

Merge remote-tracking branch 'me/no-stringly-typed-derivation-output' into validPathInfo-ca-proper-datatype

This commit is contained in:
John Ericson 2020-06-19 15:18:19 +00:00
commit 2f0e395c99
14 changed files with 108 additions and 42 deletions

View file

@ -3764,7 +3764,7 @@ void DerivationGoal::registerOutputs()
else
assert(worker.store.parseStorePath(path) == dest);
ca = FileSystemHash { i.second.hash->method, h2 };
ca = FixedOutputHash { i.second.hash->method, h2 };
}
/* Get rid of all weird permissions. This also checks that

View file

@ -2,7 +2,7 @@
namespace nix {
std::string FileSystemHash::printMethodAlgo() const {
std::string FixedOutputHash::printMethodAlgo() const {
return makeFileIngestionPrefix(method) + printHashType(*hash.type);
}
@ -33,7 +33,7 @@ std::string renderContentAddress(ContentAddress ca) {
[](TextHash th) {
return "text:" + th.hash.to_string(Base32, true);
},
[](FileSystemHash fsh) {
[](FixedOutputHash fsh) {
return makeFixedOutputCA(fsh.method, fsh.hash);
}
}, ca);
@ -55,10 +55,10 @@ ContentAddress parseContentAddress(std::string_view rawCa) {
auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos);
if (methodAndHash.substr(0,2) == "r:") {
std::string_view hashRaw = methodAndHash.substr(2,string::npos);
return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) };
return FixedOutputHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) };
} else {
std::string_view hashRaw = methodAndHash;
return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) };
return FixedOutputHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) };
}
} else {
throw Error("parseContentAddress: format not recognized; has to be text or fixed");

View file

@ -12,22 +12,12 @@ enum struct FileIngestionMethod : uint8_t {
struct TextHash {
Hash hash;
TextHash(const TextHash &) = default;
TextHash(TextHash &&) = default;
TextHash & operator = (const TextHash &) = default;
};
/// Pair of a hash, and how the file system was ingested
struct FileSystemHash {
struct FixedOutputHash {
FileIngestionMethod method;
Hash hash;
FileSystemHash(FileIngestionMethod method, Hash hash)
: method(std::move(method))
, hash(std::move(hash))
{ }
FileSystemHash(const FileSystemHash &) = default;
FileSystemHash(FileSystemHash &&) = default;
FileSystemHash & operator = (const FileSystemHash &) = default;
std::string printMethodAlgo() const;
};
@ -44,7 +34,7 @@ struct FileSystemHash {
*/
typedef std::variant<
TextHash, // for paths computed by makeTextPath() / addTextToStore
FileSystemHash // for path computed by makeFixedOutputPath
FixedOutputHash // for path computed by makeFixedOutputPath
> ContentAddress;
/* Compute the prefix to the hash algorithm which indicates how the files were

View file

@ -108,7 +108,7 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream
expect(str, ","); const auto hash = parseString(str);
expect(str, ")");
std::optional<FileSystemHash> fsh;
std::optional<FixedOutputHash> fsh;
if (hashAlgo != "") {
auto method = FileIngestionMethod::Flat;
if (string(hashAlgo, 0, 2) == "r:") {
@ -116,9 +116,9 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream
hashAlgo = string(hashAlgo, 2);
}
const HashType hashType = parseHashType(hashAlgo);
fsh = FileSystemHash {
std::move(method),
Hash(hash, hashType),
fsh = FixedOutputHash {
.method = std::move(method),
.hash = Hash(hash, hashType),
};
}
@ -406,7 +406,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store)
auto hashAlgo = readString(in);
const auto hash = readString(in);
std::optional<FileSystemHash> fsh;
std::optional<FixedOutputHash> fsh;
if (hashAlgo != "") {
auto method = FileIngestionMethod::Flat;
if (string(hashAlgo, 0, 2) == "r:") {
@ -414,9 +414,9 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store)
hashAlgo = string(hashAlgo, 2);
}
const HashType hashType = parseHashType(hashAlgo);
fsh = FileSystemHash {
std::move(method),
Hash(hash, hashType),
fsh = FixedOutputHash {
.method = std::move(method),
.hash = Hash(hash, hashType),
};
}

View file

@ -16,7 +16,7 @@ namespace nix {
struct DerivationOutput
{
StorePath path;
std::optional<FileSystemHash> hash; /* hash used for expected hash computation */
std::optional<FixedOutputHash> hash; /* hash used for expected hash computation */
};
typedef std::map<string, DerivationOutput> DerivationOutputs;

View file

@ -1079,7 +1079,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam
ValidPathInfo info(dstPath);
info.narHash = hash.first;
info.narSize = hash.second;
info.ca = FileSystemHash { method, h };
info.ca = FixedOutputHash { method, h };
registerValidPath(info);
}

View file

@ -769,7 +769,7 @@ bool ValidPathInfo::isContentAddressed(const Store & store) const
[&](TextHash th) {
return store.makeTextPath(path.name(), th.hash, references);
},
[&](FileSystemHash fsh) {
[&](FixedOutputHash fsh) {
auto refs = references;
bool hasSelfReference = false;
if (refs.count(path)) {