mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
Factor out linkOrCopy()
This commit is contained in:
parent
f1c0b2c0e1
commit
f7ce80f90a
1 changed files with 17 additions and 16 deletions
|
@ -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()
|
void DerivationGoal::startBuilder()
|
||||||
{
|
{
|
||||||
/* Right platform? */
|
/* Right platform? */
|
||||||
|
@ -2117,22 +2132,8 @@ void DerivationGoal::startBuilder()
|
||||||
throw SysError(format("getting attributes of path '%1%'") % i);
|
throw SysError(format("getting attributes of path '%1%'") % i);
|
||||||
if (S_ISDIR(st.st_mode))
|
if (S_ISDIR(st.st_mode))
|
||||||
dirsInChroot[i] = r;
|
dirsInChroot[i] = r;
|
||||||
else {
|
else
|
||||||
Path p = chrootRootDir + i;
|
linkOrCopy(r, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we're repairing, checking or rebuilding part of a
|
/* If we're repairing, checking or rebuilding part of a
|
||||||
|
|
Loading…
Reference in a new issue