mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-25 03:29:10 +08:00
correctly determine whether a folder is empty
avoid edge cases that deleting the folder if previous 32 directories are all empty early terminate if one file is found
This commit is contained in:
parent
14910d035c
commit
5c465293e9
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -311,16 +312,21 @@ func (s3a *S3ApiServer) isDirectoryAllEmpty(filerClient filer_pb.SeaweedFilerCli
|
|||||||
// println("+ isDirectoryAllEmpty", dir, name)
|
// println("+ isDirectoryAllEmpty", dir, name)
|
||||||
var fileCounter int
|
var fileCounter int
|
||||||
var subDirs []string
|
var subDirs []string
|
||||||
currentDir := parentDir+"/"+name
|
currentDir := parentDir + "/" + name
|
||||||
err = filer_pb.SeaweedList(filerClient, currentDir, "", func(entry *filer_pb.Entry, isLast bool) error {
|
var startFrom string
|
||||||
if entry.IsDirectory {
|
var isExhausted bool
|
||||||
subDirs = append(subDirs, entry.Name)
|
for fileCounter == 0 && !isExhausted {
|
||||||
} else {
|
err = filer_pb.SeaweedList(filerClient, currentDir, "", func(entry *filer_pb.Entry, isLast bool) error {
|
||||||
println("existing file", currentDir, entry.Name)
|
if entry.IsDirectory {
|
||||||
fileCounter++
|
subDirs = append(subDirs, entry.Name)
|
||||||
}
|
} else {
|
||||||
return nil
|
fileCounter++
|
||||||
}, "",false, 32)
|
}
|
||||||
|
startFrom = entry.Name
|
||||||
|
isExhausted = isExhausted || isLast
|
||||||
|
return nil
|
||||||
|
}, startFrom, false, 8)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -340,7 +346,7 @@ func (s3a *S3ApiServer) isDirectoryAllEmpty(filerClient filer_pb.SeaweedFilerCli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println("deleting empty", currentDir)
|
glog.V(1).Infof("deleting empty folder %s", currentDir)
|
||||||
if err = doDeleteEntry(filerClient, parentDir, name, true, true); err != nil {
|
if err = doDeleteEntry(filerClient, parentDir, name, true, true); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user