diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2018-10-02 11:22:13 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-10-27 18:19:13 +0100 |
commit | f7ce80f90ab364058e28989af68ba993fd8180a9 (patch) | |
tree | a03d8737f6689d089d35ca0d1d7c56b607a91380 /src | |
parent | f1c0b2c0e16154e738f342f2defa42c4d9348c4c (diff) |
Factor out linkOrCopy()
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/build.cc | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 68c2f2ce3..886c864a3 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1874,6 +1874,21 @@ static void preloadNSS() { }); } + +void linkOrCopy(const Path & from, const Path & to) +{ + if (link(from.c_str(), to.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'. FIXME: actually, why don't we just + bind-mount in this case? */ + if (errno != EMLINK) + throw SysError("linking '%s' to '%s'", to, from); + copyPath(from, to); + } +} + + void DerivationGoal::startBuilder() { /* Right platform? */ @@ -2117,22 +2132,8 @@ void DerivationGoal::startBuilder() throw SysError(format("getting attributes of path '%1%'") % i); if (S_ISDIR(st.st_mode)) dirsInChroot[i] = r; - else { - Path p = chrootRootDir + i; - debug("linking '%1%' to '%2%'", p, r); - if (link(r.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'. */ - if (errno != EMLINK) - throw SysError(format("linking '%1%' to '%2%'") % p % i); - StringSink sink; - dumpPath(r, sink); - StringSource source(*sink.s); - restorePath(p, source); - } - } + else + linkOrCopy(r, chrootRootDir + i); } /* If we're repairing, checking or rebuilding part of a |