OSDN Git Service

clean: unreadable directory may still be rmdir-able if it is empty
authorAlex Riesen <raa.lkml@gmail.com>
Fri, 1 Apr 2011 08:29:16 +0000 (10:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Apr 2011 18:16:21 +0000 (11:16 -0700)
As a last ditch effort, try rmdir(2) when we cannot read the directory
to be removed.  It may be an empty directory that we can remove without
any permission, as long as we can modify its parent directory.

Noticed by Linus.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t7300-clean.sh

diff --git a/dir.c b/dir.c
index 570b651..aa1a718 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1088,7 +1088,7 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 
        dir = opendir(path->buf);
        if (!dir)
-               return -1;
+               return rmdir(path->buf);
        if (path->buf[original_len - 1] != '/')
                strbuf_addch(path, '/');
 
index 02f67b7..9b12681 100755 (executable)
@@ -453,4 +453,11 @@ test_expect_success 'git clean -e' '
        )
 '
 
+test_expect_success SANITY 'git clean -d with an unreadable empty directory' '
+       mkdir foo &&
+       chmod a= foo &&
+       git clean -dfx foo &&
+       ! test -d foo
+'
+
 test_done