Skip to content

Commit 6cd1033

Browse files
committed
deltree: fir traversial restart
Need to go to state 2, not 4, as all files are already deleted.
1 parent b4860b2 commit 6cd1033

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/command.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,13 @@ static void perform_deltree(const char *arg)
23732373
visitation_mode[0] = 4;
23742374
dir_name[0][0] = '\0';
23752375
remove_level1_dir = false;
2376+
/* visitation mode:
2377+
* 4 - find_first on files
2378+
* 3 - find_next on files
2379+
* 2 - find_first on dirs
2380+
* 1 - find_next on dirs
2381+
* 0 - this dir is fully traversed
2382+
*/
23762383
while (subdir_level >= 0)
23772384
{
23782385
if (visitation_mode[subdir_level] == 4 || visitation_mode[subdir_level] == 2)
@@ -2401,7 +2408,7 @@ static void perform_deltree(const char *arg)
24012408
strcat(full_path_filespec, dir_name[s]);
24022409
strcat(full_path_filespec, FINDDATA_T_FILENAME(ff[subdir_level]));
24032410

2404-
if ((FINDDATA_T_ATTRIB(ff[subdir_level])&FA_DIREC) != 0)
2411+
if ((FINDDATA_T_ATTRIB(ff[subdir_level])&FA_DIREC) != 0) // found dir
24052412
{
24062413
if (visitation_mode[subdir_level] <= 2 &&
24072414
strcmp(FINDDATA_T_FILENAME(ff[subdir_level]),".") != 0 &&
@@ -2443,7 +2450,7 @@ static void perform_deltree(const char *arg)
24432450
}
24442451
}
24452452
}
2446-
else
2453+
else // found file
24472454
{
24482455
if (visitation_mode[subdir_level] > 2)
24492456
{
@@ -2469,7 +2476,7 @@ static void perform_deltree(const char *arg)
24692476
}
24702477
}
24712478
}
2472-
else
2479+
else // no more matches
24732480
{
24742481
visitation_mode[subdir_level]--;
24752482
if (visitation_mode[subdir_level] <= 0)
@@ -2495,7 +2502,7 @@ static void perform_deltree(const char *arg)
24952502
}
24962503
subdir_level--;
24972504
if (subdir_level >= 0)
2498-
visitation_mode[subdir_level] = 4; // restart from findfirst
2505+
visitation_mode[subdir_level]++; // 2 - restart from findfirst
24992506
}
25002507
}
25012508
}

0 commit comments

Comments
 (0)