diff --git a/unmount.go b/unmount.go index 7acec46..a9d78e0 100644 --- a/unmount.go +++ b/unmount.go @@ -14,10 +14,8 @@ package fuse -import "github.com/jacobsa/fuse/internal/fuseshim" - // Attempt to unmount the file system whose mount point is the supplied // directory. func Unmount(dir string) error { - return fuseshim.Unmount(dir) + return unmount(dir) } diff --git a/unmount_linux.go b/unmount_linux.go new file mode 100644 index 0000000..86abc8d --- /dev/null +++ b/unmount_linux.go @@ -0,0 +1,23 @@ +package fuseshim + +import ( + "bytes" + "fmt" + "os/exec" +) + +func unmount(dir string) (err error) { + // Call fusermount. + cmd := exec.Command("fusermount", "-u", dir) + output, err := cmd.CombinedOutput() + if err != nil { + if len(output) > 0 { + output = bytes.TrimRight(output, "\n") + err = fmt.Errorf("%v: %s", err, output) + } + + return + } + + return +} diff --git a/unmount_std.go b/unmount_std.go new file mode 100644 index 0000000..3324d6c --- /dev/null +++ b/unmount_std.go @@ -0,0 +1,18 @@ +// +build !linux + +package fuse + +import ( + "os" + "syscall" +) + +func unmount(dir string) (err error) { + err = syscall.Unmount(dir, 0) + if err != nil { + err = &os.PathError{Op: "unmount", Path: dir, Err: err} + return + } + + return +}