* When building in a chroot, make a copy of a file if hard-linking

fails.  This is likely to happen after a `nix-store --optimise',
  because some files may have 32000 links (NIX-111).
This commit is contained in:
Eelco Dolstra 2009-10-22 08:28:33 +00:00
parent 6b9f6b0222
commit 8520542071
1 changed files with 13 additions and 2 deletions

View File

@ -4,6 +4,7 @@
#include "globals.hh"
#include "local-store.hh"
#include "util.hh"
#include "archive.hh"
#include <map>
#include <iostream>
@ -1604,8 +1605,18 @@ void DerivationGoal::startBuilder()
dirsInChroot.insert(*i);
else {
Path p = chrootRootDir + *i;
if (link(i->c_str(), p.c_str()) == -1)
throw SysError(format("linking `%1%' to `%2%'") % p % *i);
if (link(i->c_str(), p.c_str()) == -1) {
/* Hard-linking fails if we exceed the maximum
link count on a file (e.g. 32000 of ext3),
which is quite possible after a `nix-store
--optimise'. Make a copy instead. */
if (errno != EMLINK)
throw SysError(format("linking `%1%' to `%2%'") % p % *i);
StringSink sink;
dumpPath(*i, sink);
StringSource source(sink.s);
restorePath(p, source);
}
}
}