fs: fix race conditions in --max-delete and --max-delete-size
This commit is contained in:
parent
a35ee30d9f
commit
e2984227bb
4 changed files with 38 additions and 22 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue