From ae4737294e91ab93526612b17950e1bc4f0b47f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Wed, 10 Apr 2024 15:17:56 +0200 Subject: [PATCH] doBind: Use our own lstat wrapper Doesn't change much, but brings a bit more consistency to the code --- src/libstore/build/local-derivation-goal.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 68c387a9d..db12af810 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -396,19 +395,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();