mirror of
https://github.com/rclone/rclone.git
synced 2025-08-18 09:30:03 +02:00
fs: fix race conditions in --max-delete and --max-delete-size
This commit is contained in:
@@ -632,20 +632,13 @@ func SuffixName(ctx context.Context, remote string) string {
|
||||
// If backupDir is set then it moves the file to there instead of
|
||||
// deleting
|
||||
func DeleteFileWithBackupDir(ctx context.Context, dst fs.Object, backupDir fs.Fs) (err error) {
|
||||
ci := fs.GetConfig(ctx)
|
||||
tr := accounting.Stats(ctx).NewCheckingTransfer(dst, "deleting")
|
||||
defer func() {
|
||||
tr.Done(ctx, err)
|
||||
}()
|
||||
deletesSize := accounting.Stats(ctx).DeletesSize(0) // file not yet deleted, we should not add at this time
|
||||
size := dst.Size()
|
||||
if int64(ci.MaxDeleteSize) != -1 && (deletesSize+size) > int64(ci.MaxDeleteSize) {
|
||||
return fserrors.FatalError(errors.New("--max-delete-size threshold reached"))
|
||||
}
|
||||
_ = accounting.Stats(ctx).DeletesSize(size) // here we count
|
||||
numDeletes := accounting.Stats(ctx).Deletes(1)
|
||||
if ci.MaxDelete != -1 && numDeletes > ci.MaxDelete {
|
||||
return fserrors.FatalError(errors.New("--max-delete threshold reached"))
|
||||
err = accounting.Stats(ctx).DeleteFile(ctx, dst.Size())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
action, actioned := "delete", "Deleted"
|
||||
if backupDir != nil {
|
||||
|
Reference in New Issue
Block a user