remove_dir_recurse(): tighten condition for removing unreadable dir

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>

Michael Haggerty committed Jan 18, 2014 at 23:48 UTC ecb2c282c0d6cdd9938ba9cf228316ebc91b397e
1 file changed +5 -2
dir.c
+5 -2
@@ -1476,8 +1476,11 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
1476 flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;
1477 dir = opendir(path->buf);
1478 if (!dir) {
1479 - /* an empty dir could be removed even if it is unreadble */
1480 - if (!keep_toplevel)
1479 + if (errno == EACCES && !keep_toplevel)
1480 + /*
1481 + * An empty dir could be removable even if it
1482 + * is unreadable:
1483 + */
1484 return rmdir(path->buf);
1485 else
1486 return -1;