1
2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18
19 package fs
20
21 import (
22 "context"
23 "errors"
24 "os/exec"
25 "runtime"
26 "time"
27
28 "bazil.org/fuse"
29 )
30
31
32
33 func Unmount(point string) error {
34 var cmd *exec.Cmd
35 switch runtime.GOOS {
36 case "darwin":
37 cmd = exec.Command("/usr/sbin/diskutil", "umount", "force", point)
38 case "linux":
39 cmd = exec.Command("fusermount", "-u", point)
40 default:
41 return errors.New("unmount: unimplemented")
42 }
43
44 errc := make(chan error, 1)
45 go func() {
46 if err := exec.Command("umount", point).Run(); err == nil {
47 errc <- err
48 }
49
50 errc <- cmd.Run()
51 }()
52 select {
53 case <-time.After(1 * time.Second):
54 return errors.New("umount timeout")
55 case err := <-errc:
56 return err
57 }
58 }
59
60 func handleEIOorEINTR(err error) error {
61 if err == nil {
62 return nil
63 }
64 if errors.Is(err, context.Canceled) {
65 return fuse.EINTR
66 } else {
67 return fuse.EIO
68 }
69 }