forked from strib/fuse
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunmount_linux.go
More file actions
35 lines (31 loc) · 888 Bytes
/
unmount_linux.go
File metadata and controls
35 lines (31 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package fuse
import (
"bytes"
"errors"
"os"
"os/exec"
sysunix "golang.org/x/sys/unix"
)
func unmount(dir string) error {
if os.Geteuid() == 0 {
// If we are running as root, we can avoid the security risks
// that come along with exec'ing fusermount and just unmount
// directly. Since we are root, let's just always detach the
// unmount to enable cases where the root user is forcing an
// upgrade of a user-based file system but there are still
// open file handles. TODO: plumb the detach flag through
// the public unmount interface.
return sysunix.Unmount(dir, sysunix.MNT_DETACH)
}
cmd := exec.Command("fusermount", "-u", dir)
output, err := cmd.CombinedOutput()
if err != nil {
if len(output) > 0 {
output = bytes.TrimRight(output, "\n")
msg := err.Error() + ": " + string(output)
err = errors.New(msg)
}
return err
}
return nil
}