clean: unreadable directory may still be rmdir-able if it is empty
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>
Alex Riesen committed
Apr 1, 2011 at 10:29 UTC
0235017eafa8dfc3a7353b7091ad5109d0beb7a5
2 files changed
+8
-1
dir.c
+1
-1
@@ -1088,7 +1088,7 @@ int remove_dir_recursively(struct strbuf *path, int flag)
1088
1089
dir = opendir(path->buf);
1090
if (!dir)
1091
- return -1;
1091
+ return rmdir(path->buf);
1092
if (path->buf[original_len - 1] != '/')
1093
strbuf_addch(path, '/');
1094
t/t7300-clean.sh
+7
@@ -453,4 +453,11 @@ test_expect_success 'git clean -e' '
453
)
454
'
455
456
+test_expect_success SANITY 'git clean -d with an unreadable empty directory' '
457
+ mkdir foo &&
458
+ chmod a= foo &&
459
+ git clean -dfx foo &&
460
+ ! test -d foo
461
+'
462
+
463
test_done