Chown files created for passAsFile

Nixpkgs' writeTextAsFile does this:

  mv "$textPath" "$n"

Since $textPath was owned by root, if $textPath is on the same
filesystem as $n, $n will be owned as root. As a result, the build
result was rejected as having suspicious ownership.

http://hydra.nixos.org/build/22836807
This commit is contained in:
Eelco Dolstra 2015-06-04 14:07:43 +02:00
parent 94378910fb
commit 07d7e7df84

View file

@ -1655,6 +1655,7 @@ void DerivationGoal::startBuilder()
environments, except those listed in the passAsFile environments, except those listed in the passAsFile
attribute. Those are passed as file names pointing to attribute. Those are passed as file names pointing to
temporary files containing the contents. */ temporary files containing the contents. */
PathSet filesToChown;
StringSet passAsFile = tokenizeString<StringSet>(get(drv.env, "passAsFile")); StringSet passAsFile = tokenizeString<StringSet>(get(drv.env, "passAsFile"));
int fileNr = 0; int fileNr = 0;
for (auto & i : drv.env) { for (auto & i : drv.env) {
@ -1663,6 +1664,7 @@ void DerivationGoal::startBuilder()
} else { } else {
Path p = tmpDir + "/.attr-" + int2String(fileNr++); Path p = tmpDir + "/.attr-" + int2String(fileNr++);
writeFile(p, i.second); writeFile(p, i.second);
filesToChown.insert(p);
env[i.first + "Path"] = p; env[i.first + "Path"] = p;
} }
} }
@ -1759,8 +1761,11 @@ void DerivationGoal::startBuilder()
buildUser.kill(); buildUser.kill();
/* Change ownership of the temporary build directory. */ /* Change ownership of the temporary build directory. */
if (chown(tmpDir.c_str(), buildUser.getUID(), buildUser.getGID()) == -1) filesToChown.insert(tmpDir);
throw SysError(format("cannot change ownership of %1%") % tmpDir);
for (auto & p : filesToChown)
if (chown(p.c_str(), buildUser.getUID(), buildUser.getGID()) == -1)
throw SysError(format("cannot change ownership of %1%") % p);
} }