prefer fusermount3 (from FUSE 3), fall back to old fusermount

fixes #84
geesefs-0-30-9
Michael Stapelberg 2020-04-23 21:10:43 +02:00
parent ffe3eb03da
commit b6e2754edf
2 changed files with 21 additions and 3 deletions

View File

@ -12,6 +12,17 @@ import (
"golang.org/x/sys/unix"
)
func findFusermount() (string, error) {
path, err := exec.LookPath("fusermount3")
if err != nil {
path, err = exec.LookPath("fusermount")
}
if err != nil {
return "", err
}
return path, nil
}
func fusermount(dir string, cfg *MountConfig) (*os.File, error) {
// Create a socket pair.
fds, err := syscall.Socketpair(syscall.AF_FILE, syscall.SOCK_STREAM, 0)
@ -29,8 +40,12 @@ func fusermount(dir string, cfg *MountConfig) (*os.File, error) {
// Start fusermount, passing it a buffer in which to write stderr.
var stderr bytes.Buffer
fusermount, err := findFusermount()
if err != nil {
return nil, err
}
cmd := exec.Command(
"fusermount",
fusermount,
"-o", cfg.toOptionsString(),
"--",
dir,

View File

@ -7,8 +7,11 @@ import (
)
func unmount(dir string) error {
// Call fusermount.
cmd := exec.Command("fusermount", "-u", dir)
fusermount, err := findFusermount()
if err != nil {
return err
}
cmd := exec.Command(fusermount, "-u", dir)
output, err := cmd.CombinedOutput()
if err != nil {
if len(output) > 0 {