mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -05:00
Simplify bucket delete - remove only bucket directory, no need to recursively traverse
This commit is contained in:
parent
7d38967f22
commit
baf66988e9
@ -41,12 +41,6 @@ func (fs Filesystem) DeleteBucket(bucket string) *probe.Error {
|
|||||||
if _, err := os.Stat(bucketDir); os.IsNotExist(err) {
|
if _, err := os.Stat(bucketDir); os.IsNotExist(err) {
|
||||||
return probe.NewError(BucketNotFound{Bucket: bucket})
|
return probe.NewError(BucketNotFound{Bucket: bucket})
|
||||||
}
|
}
|
||||||
if err := RemoveAllDirs(bucketDir); err != nil {
|
|
||||||
if err == ErrDirNotEmpty || strings.Contains(err.Error(), "directory not empty") {
|
|
||||||
return probe.NewError(BucketNotEmpty{Bucket: bucket})
|
|
||||||
}
|
|
||||||
return probe.NewError(err)
|
|
||||||
}
|
|
||||||
if err := os.Remove(bucketDir); err != nil {
|
if err := os.Remove(bucketDir); err != nil {
|
||||||
if strings.Contains(err.Error(), "directory not empty") {
|
if strings.Contains(err.Error(), "directory not empty") {
|
||||||
return probe.NewError(BucketNotEmpty{Bucket: bucket})
|
return probe.NewError(BucketNotEmpty{Bucket: bucket})
|
||||||
|
@ -43,35 +43,6 @@ func isDirEmpty(dirname string) (bool, *probe.Error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveAllDirs - removes only itself and all subdirectories
|
|
||||||
func RemoveAllDirs(path string) error {
|
|
||||||
allFiles := func(fp string, fl os.FileInfo, err error) error {
|
|
||||||
if fp == path {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if fl.Mode().IsRegular() || fl.Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
||||||
return ErrDirNotEmpty
|
|
||||||
}
|
|
||||||
if fl.Mode().IsDir() {
|
|
||||||
if err := os.Remove(fp); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err := WalkUnsorted(path, allFiles)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk walks the file tree rooted at root, calling walkFn for each file or
|
// Walk walks the file tree rooted at root, calling walkFn for each file or
|
||||||
// directory in the tree, including root.
|
// directory in the tree, including root.
|
||||||
func Walk(root string, walkFn WalkFunc) error {
|
func Walk(root string, walkFn WalkFunc) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user