libgocryptfs/checkdir.go
Jakob Unterwurzacher 58592330dc Refactor cli argument handling
Also, add the "-config" option for storing gocryptfs.conf
outside of CIPHERDIR.
2015-11-14 21:25:10 +01:00

36 lines
608 B
Go

package main
import (
"fmt"
"io/ioutil"
"os"
)
// checkDirEmpty - check if "dir" exists and is an empty directory
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)
}
// checkDir - check if "dir" exists and is a directory
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", dir)
}
return nil
}