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.
This commit is contained in:
Anis Eleuch 2023-11-27 17:36:02 -08:00 committed by GitHub
parent bd0819330d
commit 9cb94eb4a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)