pkg/fs: skip unnecessary os.Stat system call

This commit is contained in:
Brendan Ashworth 2016-03-06 23:54:43 -08:00
parent 0a0451a0fb
commit 7399d8ceaa
1 changed files with 2 additions and 5 deletions

View File

@ -36,14 +36,11 @@ func (fs Filesystem) DeleteBucket(bucket string) *probe.Error {
}
bucket = fs.denormalizeBucket(bucket)
bucketDir := filepath.Join(fs.path, bucket)
// Check if bucket exists.
if _, e := os.Stat(bucketDir); e != nil {
if e := os.Remove(bucketDir); e != nil {
// Error if there was no bucket in the first place.
if os.IsNotExist(e) {
return probe.NewError(BucketNotFound{Bucket: bucket})
}
return probe.NewError(e)
}
if e := os.Remove(bucketDir); e != nil {
// On windows the string is slightly different, handle it here.
if strings.Contains(e.Error(), "directory is not empty") {
return probe.NewError(BucketNotEmpty{Bucket: bucket})