From baf66988e9c81ff4578763162d5b1cfe847e7b72 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 30 Oct 2015 16:03:18 -0700 Subject: [PATCH] Simplify bucket delete - remove only bucket directory, no need to recursively traverse --- pkg/fs/fs-bucket.go | 6 ------ pkg/fs/fs-utils.go | 29 ----------------------------- 2 files changed, 35 deletions(-) diff --git a/pkg/fs/fs-bucket.go b/pkg/fs/fs-bucket.go index 016441c3f..5f95109e7 100644 --- a/pkg/fs/fs-bucket.go +++ b/pkg/fs/fs-bucket.go @@ -41,12 +41,6 @@ func (fs Filesystem) DeleteBucket(bucket string) *probe.Error { if _, err := os.Stat(bucketDir); os.IsNotExist(err) { 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 strings.Contains(err.Error(), "directory not empty") { return probe.NewError(BucketNotEmpty{Bucket: bucket}) diff --git a/pkg/fs/fs-utils.go b/pkg/fs/fs-utils.go index 244854ef8..3f5a627e5 100644 --- a/pkg/fs/fs-utils.go +++ b/pkg/fs/fs-utils.go @@ -43,35 +43,6 @@ func isDirEmpty(dirname string) (bool, *probe.Error) { 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 // directory in the tree, including root. func Walk(root string, walkFn WalkFunc) error {