summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-12-24 17:21:51 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2016-11-14 11:34:14 +0100
commitf94825c10c1c8f003e80859530cce8ceea1bd314 (patch)
treeac0be2c61e065532153771bb8ff33ba154e543fc
parent2d9aec99fb6a6a456aecbc354443c0c87e8a34e9 (diff)
downloadlibgit2-f94825c10c1c8f003e80859530cce8ceea1bd314.tar.gz
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.
-rw-r--r--src/fileops.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/fileops.c b/src/fileops.c
index fcc0301f9..a82202c98 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -72,8 +72,16 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
O_EXCL | O_BINARY | O_CLOEXEC, mode);
if (fd < 0) {
+ int error = errno;
giterr_set(GITERR_OS, "Failed to create locked file '%s'", path);
- return errno == EEXIST ? GIT_ELOCKED : -1;
+ switch (error) {
+ case EEXIST:
+ return GIT_ELOCKED;
+ case ENOENT:
+ return GIT_ENOTFOUND;
+ default:
+ return -1;
+ }
}
return fd;