parallel: increment progress bar before report function which may absorb the error

* sometimes, the report function may absorb the error and return nil, in those cases the bar.Add(1) method would execute even if the file deletion had failed
This commit is contained in:
Srigovind Nayak 2024-12-15 13:26:09 +05:30
parent 536ebefff4
commit 58f58a995d
No known key found for this signature in database
GPG Key ID: 09006810B7263D69
1 changed files with 4 additions and 1 deletions

View File

@ -77,13 +77,16 @@ func ParallelRemove[FT FileTypes](ctx context.Context, repo RemoverUnpacked[FT],
wg.Go(func() error { wg.Go(func() error {
for id := range fileChan { for id := range fileChan {
err := repo.RemoveUnpacked(ctx, fileType, id) err := repo.RemoveUnpacked(ctx, fileType, id)
if err == nil {
// increment counter only if no error
bar.Add(1)
}
if report != nil { if report != nil {
err = report(id, err) err = report(id, err)
} }
if err != nil { if err != nil {
return err return err
} }
bar.Add(1)
} }
return nil return nil
}) })