From 0d3c9e929bcf2ef895d886a2343eab2c19080d9a Mon Sep 17 00:00:00 2001 From: user77 Date: Tue, 30 Jun 2026 16:29:19 +0500 Subject: [PATCH] fs/operations: correct DeleteFile --backup-dir documentation DeleteFile always passes a nil backupDir to DeleteFileWithBackupDir, so it never honours --backup-dir. The previous comment said it would move the file into the backup dir when --backup-dir was in effect, which does not match the code. Update the comment to state that DeleteFile always deletes and that callers should use DeleteFileWithBackupDir when --backup-dir support is required. Also document on DeleteFileWithBackupDir that the backupDir is found with BackupDir, which is relatively expensive, so it should be looked up once outside any delete loop rather than per object. #7566 --- fs/operations/operations.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/operations/operations.go b/fs/operations/operations.go index d2220cc42..88daa6c91 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -546,7 +546,11 @@ func SuffixName(ctx context.Context, remote string) string { // and accumulating stats and errors. // // If backupDir is set then it moves the file to there instead of -// deleting +// deleting. +// +// Use BackupDir to find backupDir from --backup-dir. That lookup is +// relatively expensive, so when deleting many files do it once outside +// the loop rather than calling it for every object. func DeleteFileWithBackupDir(ctx context.Context, dst fs.Object, backupDir fs.Fs) (err error) { tr := accounting.Stats(ctx).NewCheckingTransfer(dst, "deleting") defer func() { @@ -579,8 +583,8 @@ func DeleteFileWithBackupDir(ctx context.Context, dst fs.Object, backupDir fs.Fs // DeleteFile deletes a single file respecting --dry-run and accumulating stats and errors. // -// If useBackupDir is set and --backup-dir is in effect then it moves -// the file to there instead of deleting +// DeleteFile does not honour --backup-dir: it always deletes. Call +// DeleteFileWithBackupDir instead if --backup-dir support is required. func DeleteFile(ctx context.Context, dst fs.Object) (err error) { return DeleteFileWithBackupDir(ctx, dst, nil) }