aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2024-03-30 11:23:29 -0400
committerK900 <me@0upti.me>2024-04-11 15:43:41 +0300
commitaeee22e5a17404b10dd14b5289e302eaf546e1aa (patch)
tree3bed2463ffd9916104b95fcb58be5537d65f800c /src/libstore/build
parent99845e0e01eaa2120b10c22591c43c4305f5ba51 (diff)
Merge pull request #10362 from obsidiansystems/maybeLstat
Factor out `nix::maybeLstat` (cherry-picked from commit 9b88e5284608116b7db0dbd3d5dd7a33b90d52d7) Change-Id: Id890525e847c890fad6593c594772826ac4d1d50
Diffstat (limited to 'src/libstore/build')
-rw-r--r--src/libstore/build/local-derivation-goal.cc24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index 0709dcbcb..c373ed27f 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -2044,13 +2044,13 @@ void LocalDerivationGoal::runChild()
i.first, i.second.source);
std::string path = i.first;
- struct stat st;
- if (lstat(path.c_str(), &st)) {
- if (i.second.optional && errno == ENOENT)
+ auto optSt = maybeLstat(path.c_str());
+ if (!optSt) {
+ if (i.second.optional)
continue;
- throw SysError("getting attributes of path '%s", path);
+ throw SysError("getting attributes of required path '%s", path);
}
- if (S_ISDIR(st.st_mode))
+ if (S_ISDIR(optSt->st_mode))
sandboxProfile += fmt("\t(subpath \"%s\")\n", path);
else
sandboxProfile += fmt("\t(literal \"%s\")\n", path);
@@ -2260,14 +2260,12 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
continue;
}
- struct stat st;
- if (lstat(actualPath.c_str(), &st) == -1) {
- if (errno == ENOENT)
- throw BuildError(
- "builder for '%s' failed to produce output path for output '%s' at '%s'",
- worker.store.printStorePath(drvPath), outputName, actualPath);
- throw SysError("getting attributes of path '%s'", actualPath);
- }
+ auto optSt = maybeLstat(actualPath.c_str());
+ if (!optSt)
+ throw BuildError(
+ "builder for '%s' failed to produce output path for output '%s' at '%s'",
+ worker.store.printStorePath(drvPath), outputName, actualPath);
+ struct stat & st = *optSt;
#ifndef __CYGWIN__
/* Check that the output is not group or world writable, as