mirror of https://github.com/minio/minio.git
xl: Avoid removing directory content in Delete API (#5548)
Delete & Multi Delete API should not try to remove the directory content. The only permitted case is with zero size object with a trailing slash in its name.
This commit is contained in:
parent
db9e83de62
commit
d2d49f6c6c
11
cmd/posix.go
11
cmd/posix.go
|
@ -24,6 +24,7 @@ import (
|
|||
slashpath "path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
|
@ -860,9 +861,13 @@ func deleteFile(basePath, deletePath string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Recursively go down the next path and delete again.
|
||||
// Errors for parent directories shouldn't trickle down.
|
||||
deleteFile(basePath, slashpath.Dir(deletePath))
|
||||
// Trailing slash is removed when found to ensure
|
||||
// slashpath.Dir() to work as intended.
|
||||
deletePath = strings.TrimSuffix(deletePath, slashSeparator)
|
||||
deletePath = slashpath.Dir(deletePath)
|
||||
|
||||
// Delete parent directory. Errors for parent directories shouldn't trickle down.
|
||||
deleteFile(basePath, deletePath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -777,8 +777,11 @@ func (xl xlObjects) deleteObject(bucket, object string) error {
|
|||
|
||||
var writeQuorum int
|
||||
var err error
|
||||
|
||||
isDir := hasSuffix(object, slashSeparator)
|
||||
|
||||
// If its a directory request, no need to read metadata.
|
||||
if !hasSuffix(object, slashSeparator) {
|
||||
if !isDir {
|
||||
// Read metadata associated with the object from all disks.
|
||||
metaArr, errs := readAllXLMetadata(xl.getDisks(), bucket, object)
|
||||
|
||||
|
@ -800,13 +803,20 @@ func (xl xlObjects) deleteObject(bucket, object string) error {
|
|||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(index int, disk StorageAPI) {
|
||||
go func(index int, disk StorageAPI, isDir bool) {
|
||||
defer wg.Done()
|
||||
err := cleanupDir(disk, bucket, object)
|
||||
var err error
|
||||
if isDir {
|
||||
// DeleteFile() simply tries to remove a directory
|
||||
// and will succeed only if that directory is empty.
|
||||
err = disk.DeleteFile(bucket, object)
|
||||
} else {
|
||||
err = cleanupDir(disk, bucket, object)
|
||||
}
|
||||
if err != nil && errors.Cause(err) != errVolumeNotFound {
|
||||
dErrs[index] = err
|
||||
}
|
||||
}(index, disk)
|
||||
}(index, disk, isDir)
|
||||
}
|
||||
|
||||
// Wait for all routines to finish.
|
||||
|
|
Loading…
Reference in New Issue