diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/build.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index b52f82ebbbf3..61b7d33261d9 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -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); + } } } |