Remove empty directories while removing an oobject

This commit is contained in:
Krishna Srinivas
2015-10-29 15:09:29 -07:00
parent ff7fa3637c
commit 0010f0ee10
2 changed files with 57 additions and 9 deletions

View File

@@ -18,11 +18,31 @@ package fs
import (
"errors"
"io"
"os"
"path/filepath"
"sort"
"github.com/minio/minio-xl/pkg/probe"
)
// Check if a directory is empty
func isDirEmpty(dirname string) (bool, *probe.Error) {
f, err := os.Open(dirname)
defer f.Close()
if err != nil {
return false, probe.NewError(err)
}
names, err := f.Readdirnames(1)
if err != nil && err != io.EOF {
return false, probe.NewError(err)
}
if len(names) > 0 {
return false, 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 {