Skip to content

Commit

Permalink
doBind: Use our own lstat wrapper
Browse files Browse the repository at this point in the history
Doesn't change much, but brings a bit more consistency to the code

(cherry picked from commit ae47372)
  • Loading branch information
Théophane Hufschmitt authored and github-actions[bot] committed Apr 11, 2024
1 parent ccb9779 commit af3af23
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <regex>
#include <queue>

#include <sys/stat.h>
#include <sys/un.h>
#include <fcntl.h>
#include <termios.h>
Expand Down Expand Up @@ -395,19 +394,21 @@ 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;

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);
};

if (lstat(source.c_str(), &st) == -1) {
if (optional && errno == ENOENT)
auto maybeSt = maybeLstat(source);
if (!maybeSt) {
if (optional)
return;
else
throw SysError("getting attributes of path '%1%'", source);
}
auto st = *maybeSt;

if (S_ISDIR(st.st_mode)) {
createDirs(target);
bindMount();
Expand Down

0 comments on commit af3af23

Please sign in to comment.