7d477d692b
OSXFuse automatically creates the mountpoint if it is below /Volumes because this would require root permissions which the user might not have. Reported at https://github.com/rfjakob/gocryptfs/issues/194
37 lines
666 B
Go
37 lines
666 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// checkDirEmpty - check if "dir" exists and is an empty directory.
|
|
// Returns an *os.PathError if Stat() on the path fails.
|
|
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
|
|
}
|