From ecb2c282c0d6cdd9938ba9cf228316ebc91b397e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sat, 18 Jan 2014 23:48:56 +0100 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- dir.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 23b6de4703..11e1520262 100644 --- a/dir.c +++ b/dir.c @@ -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; -- 2.11.4.GIT