aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/builtins/buildenv.cc
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/builtins/buildenv.cc
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/builtins/buildenv.cc')
-rw-r--r--src/libstore/builtins/buildenv.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc
index eb68d5a33..61c729d27 100644
--- a/src/libstore/builtins/buildenv.cc
+++ b/src/libstore/builtins/buildenv.cc
@@ -63,9 +63,9 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
continue;
else if (S_ISDIR(srcSt.st_mode)) {
- struct stat dstSt;
- auto res = lstat(dstFile.c_str(), &dstSt);
- if (res == 0) {
+ auto dstStOpt = maybeLstat(dstFile.c_str());
+ if (dstStOpt) {
+ auto & dstSt = *dstStOpt;
if (S_ISDIR(dstSt.st_mode)) {
createLinks(state, srcFile, dstFile, priority);
continue;
@@ -81,14 +81,13 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
createLinks(state, srcFile, dstFile, priority);
continue;
}
- } else if (errno != ENOENT)
- throw SysError("getting status of '%1%'", dstFile);
+ }
}
else {
- struct stat dstSt;
- auto res = lstat(dstFile.c_str(), &dstSt);
- if (res == 0) {
+ auto dstStOpt = maybeLstat(dstFile.c_str());
+ if (dstStOpt) {
+ auto & dstSt = *dstStOpt;
if (S_ISLNK(dstSt.st_mode)) {
auto prevPriority = state.priorities[dstFile];
if (prevPriority == priority)
@@ -103,8 +102,7 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
throw SysError("unlinking '%1%'", dstFile);
} else if (S_ISDIR(dstSt.st_mode))
throw Error("collision between non-directory '%1%' and directory '%2%'", srcFile, dstFile);
- } else if (errno != ENOENT)
- throw SysError("getting status of '%1%'", dstFile);
+ }
}
createSymlink(srcFile, dstFile);