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>
This commit is contained in:

committed by
Junio C Hamano

parent
835e3c992f
commit
470a91ef75
5
refs.c
5
refs.c
@ -1960,14 +1960,16 @@ static int remove_empty_directories(const char *file)
|
|||||||
* only empty directories), remove them.
|
* only empty directories), remove them.
|
||||||
*/
|
*/
|
||||||
struct strbuf path;
|
struct strbuf path;
|
||||||
int result;
|
int result, save_errno;
|
||||||
|
|
||||||
strbuf_init(&path, 20);
|
strbuf_init(&path, 20);
|
||||||
strbuf_addstr(&path, file);
|
strbuf_addstr(&path, file);
|
||||||
|
|
||||||
result = remove_dir_recursively(&path, REMOVE_DIR_EMPTY_ONLY);
|
result = remove_dir_recursively(&path, REMOVE_DIR_EMPTY_ONLY);
|
||||||
|
save_errno = errno;
|
||||||
|
|
||||||
strbuf_release(&path);
|
strbuf_release(&path);
|
||||||
|
errno = save_errno;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2056,6 +2058,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
|
|||||||
return logs_found;
|
return logs_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function should make sure errno is meaningful on error */
|
||||||
static struct ref_lock *lock_ref_sha1_basic(const char *refname,
|
static struct ref_lock *lock_ref_sha1_basic(const char *refname,
|
||||||
const unsigned char *old_sha1,
|
const unsigned char *old_sha1,
|
||||||
int flags, int *type_p)
|
int flags, int *type_p)
|
||||||
|
Reference in New Issue
Block a user