aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIlya K <me@0upti.me>2024-04-11 19:08:33 +0000
committerGerrit Code Review <gerrit@lix>2024-04-11 19:08:33 +0000
commitd363bc2f123876b2524ca76997f27f9f4e0a2391 (patch)
tree81591ca53715775a0edd4f18a4aaa9c8186f6909 /src
parente4a8c01bdf81c6a66ba1b21d6c4f7a8913a64306 (diff)
parent07b627cc6d1224df75ea2d4979c4c83bb67392f1 (diff)
Merge "Merge pull request #10456 from NixOS/fixpermdeniedbind" into main
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build/local-derivation-goal.cc26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index c373ed27f..588fe33ba 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -389,21 +389,33 @@ void LocalDerivationGoal::cleanupPostOutputsRegisteredModeNonCheck()
#if __linux__
static void doBind(const Path & source, const Path & target, bool optional = false) {
debug("bind mounting '%1%' to '%2%'", source, target);
- struct stat st;
- if (stat(source.c_str(), &st) == -1) {
- if (optional && errno == ENOENT)
+
+ auto bindMount = [&]() {
+ if (mount(source.c_str(), target.c_str(), "", MS_BIND | MS_REC, 0) == -1)
+ throw SysError("bind mount from '%1%' to '%2%' failed", source, target);
+ };
+
+ auto maybeSt = maybeLstat(source);
+ if (!maybeSt) {
+ if (optional)
return;
else
throw SysError("getting attributes of path '%1%'", source);
}
- if (S_ISDIR(st.st_mode))
+ auto st = *maybeSt;
+
+ if (S_ISDIR(st.st_mode)) {
createDirs(target);
- else {
+ bindMount();
+ } else if (S_ISLNK(st.st_mode)) {
+ // Symlinks can (apparently) not be bind-mounted, so just copy it
+ createDirs(dirOf(target));
+ copyFile(source, target, /* andDelete */ false);
+ } else {
createDirs(dirOf(target));
writeFile(target, "");
+ bindMount();
}
- if (mount(source.c_str(), target.c_str(), "", MS_BIND | MS_REC, 0) == -1)
- throw SysError("bind mount from '%1%' to '%2%' failed", source, target);
};
#endif