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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user