From 9cb94eb4a919090fb549aa456927df441df848c4 Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Mon, 27 Nov 2023 17:36:02 -0800 Subject: [PATCH] cleaning up will delete instead of rename to trash with full disk err (#18534) moveToTrash() function moves a folder to .trash, for example, when doing some object deletions: a data dir that has many parts will be renamed to the trash folder; However, ENOSPC is a valid error from rename(), and it can cripple a user trying to free some space in an entire disk situation. Therefore, this commit will try to do a recursive delete in that case. --- cmd/xl-storage.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index 0ee559b8f..b76f706c5 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -1095,20 +1095,29 @@ func (s *xlStorage) DeleteVersions(ctx context.Context, volume string, versions return errs } -func (s *xlStorage) moveToTrash(filePath string, recursive, force bool) error { +func (s *xlStorage) moveToTrash(filePath string, recursive, force bool) (err error) { pathUUID := mustGetUUID() targetPath := pathutil.Join(s.drivePath, minioMetaTmpDeletedBucket, pathUUID) if recursive { - if err := renameAll(filePath, targetPath, pathutil.Join(s.drivePath, minioMetaTmpDeletedBucket)); err != nil { - return err - } + err = renameAll(filePath, targetPath, pathutil.Join(s.drivePath, minioMetaTmpDeletedBucket)) } else { - if err := Rename(filePath, targetPath); err != nil { - return err + err = Rename(filePath, targetPath) + } + + // ENOSPC is a valid error from rename(); remove instead of rename in that case + if err == errDiskFull { + if recursive { + err = removeAll(filePath) + } else { + err = Remove(filePath) } } + if err != nil { + return err + } + // immediately purge the target if force { removeAll(targetPath)