mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
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:
parent
bd0819330d
commit
9cb94eb4a9
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user