libgocryptfs/checkdir.go

34 lines
486 B
Go
Raw Normal View History

package main
import (
"fmt"
2015-10-11 18:51:56 +02:00
"io/ioutil"
"os"
)
func checkDirEmpty(dir string) error {
err := checkDir(dir)
if err != nil {
return err
}
entries, err := ioutil.ReadDir(dir)
if err != nil {
return err
}
if len(entries) == 0 {
return nil
}
return fmt.Errorf("directory %s not empty", dir)
}
func checkDir(dir string) error {
fi, err := os.Stat(dir)
if err != nil {
return err
}
2015-10-11 18:51:56 +02:00
if !fi.IsDir() {
return fmt.Errorf("%s is not a directory", dir)
}
return nil
}