summaryrefslogtreecommitdiff
path: root/checkdir.go
diff options
context:
space:
mode:
Diffstat (limited to 'checkdir.go')
-rw-r--r--checkdir.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/checkdir.go b/checkdir.go
new file mode 100644
index 0000000..182bf97
--- /dev/null
+++ b/checkdir.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "io/ioutil"
+ "fmt"
+ "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
+ }
+ if ! fi.IsDir() {
+ return fmt.Errorf("%s is not a directory")
+ }
+ return nil
+}