Browse Source

s3: Critical - S3 Delete Multiple Objects, delete the bucket

fix https://github.com/chrislusf/seaweedfs/issues/1806
pull/1811/head
Chris Lu 4 years ago
parent
commit
8b169aa47c
  1. 9
      weed/s3api/s3api_object_handlers.go

9
weed/s3api/s3api_object_handlers.go

@ -185,7 +185,7 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
for _, object := range deleteObjects.Objects { for _, object := range deleteObjects.Objects {
lastSeparator := strings.LastIndex(object.ObjectName, "/") lastSeparator := strings.LastIndex(object.ObjectName, "/")
parentDirectoryPath, entryName, isDeleteData, isRecursive := "/", object.ObjectName, true, false
parentDirectoryPath, entryName, isDeleteData, isRecursive := "", object.ObjectName, true, false
if lastSeparator > 0 && lastSeparator+1 < len(object.ObjectName) { if lastSeparator > 0 && lastSeparator+1 < len(object.ObjectName) {
entryName = object.ObjectName[lastSeparator+1:] entryName = object.ObjectName[lastSeparator+1:]
parentDirectoryPath = "/" + object.ObjectName[:lastSeparator] parentDirectoryPath = "/" + object.ObjectName[:lastSeparator]
@ -208,7 +208,7 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
// purge empty folders, only checking folders with deletions // purge empty folders, only checking folders with deletions
for len(directoriesWithDeletion) > 0 { for len(directoriesWithDeletion) > 0 {
directoriesWithDeletion = doDeleteEmptyDirectories(client, directoriesWithDeletion)
directoriesWithDeletion = s3a.doDeleteEmptyDirectories(client, directoriesWithDeletion)
} }
return nil return nil
@ -224,7 +224,7 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
} }
func doDeleteEmptyDirectories(client filer_pb.SeaweedFilerClient, directoriesWithDeletion map[string]int) (newDirectoriesWithDeletion map[string]int) {
func (s3a *S3ApiServer) doDeleteEmptyDirectories(client filer_pb.SeaweedFilerClient, directoriesWithDeletion map[string]int) (newDirectoriesWithDeletion map[string]int) {
var allDirs []string var allDirs []string
for dir, _ := range directoriesWithDeletion { for dir, _ := range directoriesWithDeletion {
allDirs = append(allDirs, dir) allDirs = append(allDirs, dir)
@ -235,6 +235,9 @@ func doDeleteEmptyDirectories(client filer_pb.SeaweedFilerClient, directoriesWit
newDirectoriesWithDeletion = make(map[string]int) newDirectoriesWithDeletion = make(map[string]int)
for _, dir := range allDirs { for _, dir := range allDirs {
parentDir, dirName := util.FullPath(dir).DirAndName() parentDir, dirName := util.FullPath(dir).DirAndName()
if parentDir == s3a.option.BucketsPath {
continue
}
if err := doDeleteEntry(client, parentDir, dirName, false, false); err != nil { if err := doDeleteEntry(client, parentDir, dirName, false, false); err != nil {
glog.V(4).Infof("directory %s has %d deletion but still not empty: %v", dir, directoriesWithDeletion[dir], err) glog.V(4).Infof("directory %s has %d deletion but still not empty: %v", dir, directoriesWithDeletion[dir], err)
} else { } else {

Loading…
Cancel
Save