box: use atomic types

This commit is contained in:
Roberto Ricci 2023-08-18 15:14:51 +02:00 committed by Nick Craig-Wood
parent 45458f2cdb
commit b6e7148daf

View File

@ -1121,7 +1121,7 @@ func (f *Fs) deletePermanently(ctx context.Context, itemType, id string) error {
// CleanUp empties the trash // CleanUp empties the trash
func (f *Fs) CleanUp(ctx context.Context) (err error) { func (f *Fs) CleanUp(ctx context.Context) (err error) {
var ( var (
deleteErrors = int64(0) deleteErrors atomic.Uint64
concurrencyControl = make(chan struct{}, fs.GetConfig(ctx).Checkers) concurrencyControl = make(chan struct{}, fs.GetConfig(ctx).Checkers)
wg sync.WaitGroup wg sync.WaitGroup
) )
@ -1137,7 +1137,7 @@ func (f *Fs) CleanUp(ctx context.Context) (err error) {
err := f.deletePermanently(ctx, item.Type, item.ID) err := f.deletePermanently(ctx, item.Type, item.ID)
if err != nil { if err != nil {
fs.Errorf(f, "failed to delete trash item %q (%q): %v", item.Name, item.ID, err) fs.Errorf(f, "failed to delete trash item %q (%q): %v", item.Name, item.ID, err)
atomic.AddInt64(&deleteErrors, 1) deleteErrors.Add(1)
} }
}() }()
} else { } else {
@ -1146,8 +1146,8 @@ func (f *Fs) CleanUp(ctx context.Context) (err error) {
return false return false
}) })
wg.Wait() wg.Wait()
if deleteErrors != 0 { if deleteErrors.Load() != 0 {
return fmt.Errorf("failed to delete %d trash items", deleteErrors) return fmt.Errorf("failed to delete %d trash items", deleteErrors.Load())
} }
return err return err
} }