Skip to content

Commit f94825c

Browse files
committed
fileops: save errno and report file existence
We need to save the errno, lest we clobber it in the giterr_set() call. Also add code for reporting that a path component is missing, which is a distinct failure mode.
1 parent 2d9aec9 commit f94825c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/fileops.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
7272
O_EXCL | O_BINARY | O_CLOEXEC, mode);
7373

7474
if (fd < 0) {
75+
int error = errno;
7576
giterr_set(GITERR_OS, "Failed to create locked file '%s'", path);
76-
return errno == EEXIST ? GIT_ELOCKED : -1;
77+
switch (error) {
78+
case EEXIST:
79+
return GIT_ELOCKED;
80+
case ENOENT:
81+
return GIT_ENOTFOUND;
82+
default:
83+
return -1;
84+
}
7785
}
7886

7987
return fd;

0 commit comments

Comments
 (0)