mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-19 06:53:32 +08:00
AllowEmptyFolder checks during object deletion
This commit is contained in:
parent
d521466a37
commit
e6bfd061c7
@ -27,16 +27,36 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque
|
||||
bucket, object := s3_constants.GetBucketAndObject(r)
|
||||
glog.V(3).Infof("DeleteObjectHandler %s %s", bucket, object)
|
||||
|
||||
destUrl := s3a.toFilerUrl(bucket, object)
|
||||
object = urlPathEscape(removeDuplicateSlashes(object))
|
||||
|
||||
s3a.proxyToFiler(w, r, destUrl, true, func(proxyResponse *http.Response, w http.ResponseWriter) (statusCode int) {
|
||||
statusCode = http.StatusNoContent
|
||||
for k, v := range proxyResponse.Header {
|
||||
w.Header()[k] = v
|
||||
s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
err := doDeleteEntry(client, s3a.option.BucketsPath+"/"+bucket, object, true, false)
|
||||
if err != nil {
|
||||
// skip deletion error, usually the file is not found
|
||||
return nil
|
||||
}
|
||||
w.WriteHeader(statusCode)
|
||||
return statusCode
|
||||
|
||||
if s3a.option.AllowEmptyFolder {
|
||||
return nil
|
||||
}
|
||||
|
||||
directoriesWithDeletion := make(map[string]int)
|
||||
lastSeparator := strings.LastIndex(object, "/")
|
||||
if lastSeparator > 0 {
|
||||
parentDirectoryPath := fmt.Sprintf("%s/%s", s3a.option.BucketsPath, bucket)
|
||||
directoriesWithDeletion[parentDirectoryPath]++
|
||||
|
||||
// purge empty folders, only checking folders with deletions
|
||||
for len(directoriesWithDeletion) > 0 {
|
||||
directoriesWithDeletion = s3a.doDeleteEmptyDirectories(client, directoriesWithDeletion)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// / ObjectIdentifier carries key name for the object to delete.
|
||||
|
@ -415,9 +415,9 @@ func (s3a *S3ApiServer) doListFilerEntries(client filer_pb.SeaweedFilerClient, d
|
||||
} else {
|
||||
var isEmpty bool
|
||||
if !s3a.option.AllowEmptyFolder && entry.IsOlderDir() {
|
||||
if isEmpty, err = s3a.ensureDirectoryAllEmpty(client, dir, entry.Name); err != nil {
|
||||
glog.Errorf("check empty folder %s: %v", dir, err)
|
||||
}
|
||||
//if isEmpty, err = s3a.ensureDirectoryAllEmpty(client, dir, entry.Name); err != nil {
|
||||
// glog.Errorf("check empty folder %s: %v", dir, err)
|
||||
//}
|
||||
}
|
||||
if !isEmpty {
|
||||
eachEntryFn(dir, entry)
|
||||
|
Loading…
Reference in New Issue
Block a user