Merge pull request #3297 from edef1c/passasfile-hash

passAsFile: hash the attribute name instead of numbering sequentially
This commit is contained in:
Eelco Dolstra 2020-01-03 00:08:23 +01:00 committed by GitHub
commit 3ad4a332eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2455,12 +2455,12 @@ void DerivationGoal::initTmpDir() {
if (!parsedDrv->getStructuredAttrs()) { if (!parsedDrv->getStructuredAttrs()) {
StringSet passAsFile = tokenizeString<StringSet>(get(drv->env, "passAsFile").value_or("")); StringSet passAsFile = tokenizeString<StringSet>(get(drv->env, "passAsFile").value_or(""));
int fileNr = 0;
for (auto & i : drv->env) { for (auto & i : drv->env) {
if (passAsFile.find(i.first) == passAsFile.end()) { if (passAsFile.find(i.first) == passAsFile.end()) {
env[i.first] = i.second; env[i.first] = i.second;
} else { } else {
string fn = ".attr-" + std::to_string(fileNr++); auto hash = hashString(htSHA256, i.first);
string fn = ".attr-" + hash.to_string();
Path p = tmpDir + "/" + fn; Path p = tmpDir + "/" + fn;
writeFile(p, i.second); writeFile(p, i.second);
chownToBuilder(p); chownToBuilder(p);