symlinks: do not include startup_info->original_cwd in dir removal

symlinks has a pair of schedule_dir_for_removal() and
remove_scheduled_dirs() functions that ensure that directories made
empty by removing other files also themselves get removed.  However, we
want to exclude startup_info->original_cwd and leave it around.  This
avoids the user getting confused by subsequent git commands (and non-git
commands) that would otherwise report confusing messages about being
unable to read the current working directory.

Acked-by: Derrick Stolee <stolee@gmail.com>
Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren
2021-12-09 05:08:29 +00:00
committed by Junio C Hamano
parent 0b0ee3388c
commit 00fcce285d
2 changed files with 12 additions and 6 deletions

View File

@ -279,7 +279,9 @@ static void do_remove_scheduled_dirs(int new_len)
{
while (removal.len > new_len) {
removal.buf[removal.len] = '\0';
if (rmdir(removal.buf))
if ((startup_info->original_cwd &&
!strcmp(removal.buf, startup_info->original_cwd)) ||
rmdir(removal.buf))
break;
do {
removal.len--;
@ -293,6 +295,10 @@ void schedule_dir_for_removal(const char *name, int len)
{
int match_len, last_slash, i, previous_slash;
if (startup_info->original_cwd &&
!strcmp(name, startup_info->original_cwd))
return; /* Do not remove the current working directory */
match_len = last_slash = i =
longest_path_match(name, len, removal.buf, removal.len,
&previous_slash);