1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-05-20 18:31:53 +02:00

AllowEmptyFolder checks during object deletion

This commit is contained in:
chrislu 2024-04-29 06:25:06 -07:00
parent d521466a37
commit e6bfd061c7
2 changed files with 30 additions and 10 deletions

View file

@ -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.

View file

@ -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)