aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/fuse/swarmfs_util.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/fuse/swarmfs_util.go')
-rw-r--r--swarm/fuse/swarmfs_util.go42
1 files changed, 13 insertions, 29 deletions
diff --git a/swarm/fuse/swarmfs_util.go b/swarm/fuse/swarmfs_util.go
index d20ab258e..d39966c0e 100644
--- a/swarm/fuse/swarmfs_util.go
+++ b/swarm/fuse/swarmfs_util.go
@@ -19,47 +19,31 @@
package fuse
import (
+ "context"
"fmt"
- "github.com/ethereum/go-ethereum/log"
"os/exec"
"runtime"
- "time"
-)
-func externalUnMount(mountPoint string) error {
+ "github.com/ethereum/go-ethereum/log"
+)
- var cmd *exec.Cmd
+func externalUnmount(mountPoint string) error {
+ ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout)
+ defer cancel()
+ // Try generic umount.
+ if err := exec.CommandContext(ctx, "umount", mountPoint).Run(); err == nil {
+ return nil
+ }
+ // Try FUSE-specific commands if umount didn't work.
switch runtime.GOOS {
-
case "darwin":
- cmd = exec.Command("/usr/bin/diskutil", "umount", "force", mountPoint)
-
+ return exec.CommandContext(ctx, "diskutil", "umount", "force", mountPoint).Run()
case "linux":
- cmd = exec.Command("fusermount", "-u", mountPoint)
-
+ return exec.CommandContext(ctx, "fusermount", "-u", mountPoint).Run()
default:
return fmt.Errorf("unmount: unimplemented")
}
-
- errc := make(chan error, 1)
- go func() {
- defer close(errc)
-
- if err := exec.Command("umount", mountPoint).Run(); err == nil {
- return
- }
- errc <- cmd.Run()
- }()
-
- select {
-
- case <-time.After(unmountTimeout):
- return fmt.Errorf("umount timeout")
-
- case err := <-errc:
- return err
- }
}
func addFileToSwarm(sf *SwarmFile, content []byte, size int) error {