Browse Source

AllowEmptyFolder checks during object deletion

pull/5548/head
chrislu 8 months ago
parent
commit
e6bfd061c7
  1. 34
      weed/s3api/s3api_object_handlers_delete.go
  2. 6
      weed/s3api/s3api_object_handlers_list.go

34
weed/s3api/s3api_object_handlers_delete.go

@ -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
}
if s3a.option.AllowEmptyFolder {
return nil
}
w.WriteHeader(statusCode)
return statusCode
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.

6
weed/s3api/s3api_object_handlers_list.go

@ -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…
Cancel
Save