Skip to content

Commit

Permalink
clean: unreadable directory may still be rmdir-able if it is empty
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alex Riesen authored and Junio C Hamano committed Apr 1, 2011
1 parent 2352570 commit 0235017
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');

Expand Down
7 changes: 7 additions & 0 deletions t/t7300-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0235017

Please sign in to comment.