refs.c: make remove_empty_directories always set errno to something sane
Making errno when returning from remove_empty_directories() more obviously meaningful, which should provide some peace of mind for people auditing lock_ref_sha1_basic. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>
Ronnie Sahlberg committed
Jun 20, 2014 at 07:42 UTC
470a91ef75d61d102c9cb655a7b8ea1555337d2d
1 file changed
+4
-1
refs.c
+4
-1
@@ -1960,14 +1960,16 @@ static int remove_empty_directories(const char *file)
1960
* only empty directories), remove them.
1961
*/
1962
struct strbuf path;
1963
- int result;
1963
+ int result, save_errno;
1964
1965
strbuf_init(&path, 20);
1966
strbuf_addstr(&path, file);
1967
1968
result = remove_dir_recursively(&path, REMOVE_DIR_EMPTY_ONLY);
1969
+ save_errno = errno;
1970
1971
strbuf_release(&path);
1972
+ errno = save_errno;
1973
1974
return result;
1975
}
@@ -2056,6 +2058,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
2058
return logs_found;
2059
}
2060
2061
+/* This function should make sure errno is meaningful on error */
2062
static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2063
const unsigned char *old_sha1,
2064
int flags, int *type_p)