safe_create_leading_directories(): set errno on SCLD_EXISTS
The exit path for SCLD_EXISTS wasn't setting errno, which some callers use to generate error messages for the user. Fix the problem and document that the function sets errno correctly to help avoid similar regressions in the future. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jan 6, 2017 at 17:22 UTC
204a047f23462e4931eb00c367818d9870237827
2 files changed
+6
-3
cache.h
+3
-2
@@ -1031,8 +1031,9 @@ int adjust_shared_perm(const char *path);
1031
1032
/*
1033
* Create the directory containing the named path, using care to be
1034
- * somewhat safe against races. Return one of the scld_error values
1035
- * to indicate success/failure.
1034
+ * somewhat safe against races. Return one of the scld_error values to
1035
+ * indicate success/failure. On error, set errno to describe the
1036
+ * problem.
1037
*
1038
* SCLD_VANISHED indicates that one of the ancestor directories of the
1039
* path existed at one point during the function call and then
sha1_file.c
+3
-1
@@ -137,8 +137,10 @@ enum scld_error safe_create_leading_directories(char *path)
137
*slash = '\0';
138
if (!stat(path, &st)) {
139
/* path exists */
140
- if (!S_ISDIR(st.st_mode))
140
+ if (!S_ISDIR(st.st_mode)) {
141
+ errno = ENOTDIR;
142
ret = SCLD_EXISTS;
143
+ }
144
} else if (mkdir(path, 0777)) {
145
if (errno == EEXIST &&
146
!stat(path, &st) && S_ISDIR(st.st_mode))