Skip to content

Commit 0235017

Browse files
raalkmlgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2352570 commit 0235017

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ int remove_dir_recursively(struct strbuf *path, int flag)
10881088

10891089
dir = opendir(path->buf);
10901090
if (!dir)
1091-
return -1;
1091+
return rmdir(path->buf);
10921092
if (path->buf[original_len - 1] != '/')
10931093
strbuf_addch(path, '/');
10941094

t/t7300-clean.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,11 @@ test_expect_success 'git clean -e' '
453453
)
454454
'
455455

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+
456463
test_done

0 commit comments

Comments
 (0)