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.
master
Anis Elleuch 7 years ago committed by kannappanr
parent db9e83de62
commit d2d49f6c6c
  1. 11
      cmd/posix.go
  2. 18
      cmd/xl-v1-object.go

@ -24,6 +24,7 @@ import (
slashpath "path" slashpath "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
@ -860,9 +861,13 @@ func deleteFile(basePath, deletePath string) error {
return err return err
} }
// Recursively go down the next path and delete again. // Trailing slash is removed when found to ensure
// Errors for parent directories shouldn't trickle down. // slashpath.Dir() to work as intended.
deleteFile(basePath, slashpath.Dir(deletePath)) 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 return nil
} }

@ -777,8 +777,11 @@ func (xl xlObjects) deleteObject(bucket, object string) error {
var writeQuorum int var writeQuorum int
var err error var err error
isDir := hasSuffix(object, slashSeparator)
// If its a directory request, no need to read metadata. // 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. // Read metadata associated with the object from all disks.
metaArr, errs := readAllXLMetadata(xl.getDisks(), bucket, object) metaArr, errs := readAllXLMetadata(xl.getDisks(), bucket, object)
@ -800,13 +803,20 @@ func (xl xlObjects) deleteObject(bucket, object string) error {
continue continue
} }
wg.Add(1) wg.Add(1)
go func(index int, disk StorageAPI) { go func(index int, disk StorageAPI, isDir bool) {
defer wg.Done() 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 { if err != nil && errors.Cause(err) != errVolumeNotFound {
dErrs[index] = err dErrs[index] = err
} }
}(index, disk) }(index, disk, isDir)
} }
// Wait for all routines to finish. // Wait for all routines to finish.

Loading…
Cancel
Save