Skip to content

Commit

Permalink
remove_dir_recurse(): tighten condition for removing unreadable dir
Browse files Browse the repository at this point in the history
If opendir() fails on the top-level directory, it makes sense to try
to delete it anyway--but only if the failure was due to EACCES.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jan 21, 2014
1 parent e5c223e commit ecb2c28
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,8 +1476,11 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;
dir = opendir(path->buf);
if (!dir) {
/* an empty dir could be removed even if it is unreadble */
if (!keep_toplevel)
if (errno == EACCES && !keep_toplevel)
/*
* An empty dir could be removable even if it
* is unreadable:
*/
return rmdir(path->buf);
else
return -1;
Expand Down

0 comments on commit ecb2c28

Please sign in to comment.