Skip to content

Commit 61f31e5

Browse files
authored
Merge pull request #5476 from rob-deutsch/fix/5475
fix fuse unmount test
2 parents 370bd22 + 20f5cf7 commit 61f31e5

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

fuse/mount/mount.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,9 @@ func ForceUnmount(m Mount) error {
3838
point := m.MountPoint()
3939
log.Warningf("Force-Unmounting %s...", point)
4040

41-
var cmd *exec.Cmd
42-
switch runtime.GOOS {
43-
case "darwin":
44-
cmd = exec.Command("diskutil", "umount", "force", point)
45-
case "linux":
46-
cmd = exec.Command("fusermount", "-u", point)
47-
default:
48-
return fmt.Errorf("unmount: unimplemented")
41+
cmd, err := UnmountCmd(point)
42+
if err != nil {
43+
return err
4944
}
5045

5146
errc := make(chan error, 1)
@@ -69,6 +64,19 @@ func ForceUnmount(m Mount) error {
6964
}
7065
}
7166

67+
// UnmountCmd creates an exec.Cmd that is GOOS-specific
68+
// for unmount a FUSE mount
69+
func UnmountCmd(point string) (*exec.Cmd, error) {
70+
switch runtime.GOOS {
71+
case "darwin":
72+
return exec.Command("diskutil", "umount", "force", point), nil
73+
case "linux":
74+
return exec.Command("fusermount", "-u", point), nil
75+
default:
76+
return nil, fmt.Errorf("unmount: unimplemented")
77+
}
78+
}
79+
7280
// ForceUnmountManyTimes attempts to forcibly unmount a given mount,
7381
// many times. It does so by calling diskutil or fusermount directly.
7482
// Attempts a given number of times.

fuse/node/mount_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package node
55
import (
66
"io/ioutil"
77
"os"
8-
"os/exec"
98
"testing"
109
"time"
1110

@@ -77,24 +76,21 @@ func TestExternalUnmount(t *testing.T) {
7776
}
7877

7978
// Run shell command to externally unmount the directory
80-
cmd := "fusermount"
81-
args := []string{"-u", ipnsDir}
82-
if err := exec.Command(cmd, args...).Run(); err != nil {
79+
cmd, err := mount.UnmountCmd(ipfsDir)
80+
if err != nil {
81+
t.Fatal(err)
82+
}
83+
84+
if err := cmd.Run(); err != nil {
8385
t.Fatal(err)
8486
}
8587

8688
// TODO(noffle): it takes a moment for the goroutine that's running fs.Serve to be notified and do its cleanup.
8789
time.Sleep(time.Millisecond * 100)
8890

89-
// Attempt to unmount IPNS; check that it was already unmounted.
90-
err = node.Mounts.Ipns.Unmount()
91-
if err != mount.ErrNotMounted {
92-
t.Fatal("Unmount should have failed")
93-
}
94-
9591
// Attempt to unmount IPFS; it should unmount successfully.
9692
err = node.Mounts.Ipfs.Unmount()
97-
if err != nil {
98-
t.Fatal(err)
93+
if err != mount.ErrNotMounted {
94+
t.Fatal("Unmount should have failed")
9995
}
10096
}

0 commit comments

Comments
 (0)