aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/fuse
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-05-30 17:21:59 +0800
committerFelix Lange <fjl@twurst.com>2017-06-21 15:56:58 +0800
commit50c18e6eb818c26ff7b96c37a195686581783f6b (patch)
treee9c3f7a7ad2a35942a25a1fad5c7e1be0b2b7395 /swarm/fuse
parent693d9ccbfbbcf7c32d3ff9fd8a432941e129a4ac (diff)
downloadgo-tangerine-50c18e6eb818c26ff7b96c37a195686581783f6b.tar.gz
go-tangerine-50c18e6eb818c26ff7b96c37a195686581783f6b.tar.zst
go-tangerine-50c18e6eb818c26ff7b96c37a195686581783f6b.zip
swarm/fuse: simplify externalUnmount
The code looked for /usr/bin/diskutil on darwin, but it's actually located in /usr/sbin. Fix that by not specifying the absolute path. Also remove weird timeout construction and extra whitespace.
Diffstat (limited to 'swarm/fuse')
-rw-r--r--swarm/fuse/swarmfs_unix.go13
-rw-r--r--swarm/fuse/swarmfs_util.go42
2 files changed, 20 insertions, 35 deletions
diff --git a/swarm/fuse/swarmfs_unix.go b/swarm/fuse/swarmfs_unix.go
index f4eecef24..1a8390a4b 100644
--- a/swarm/fuse/swarmfs_unix.go
+++ b/swarm/fuse/swarmfs_unix.go
@@ -19,18 +19,19 @@
package fuse
import (
- "bazil.org/fuse"
- "bazil.org/fuse/fs"
"errors"
"fmt"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/swarm/api"
"os"
"path/filepath"
"strings"
"sync"
"time"
+
+ "bazil.org/fuse"
+ "bazil.org/fuse/fs"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/log"
+ "github.com/ethereum/go-ethereum/swarm/api"
)
var (
@@ -203,7 +204,7 @@ func (self *SwarmFS) Unmount(mountpoint string) (*MountInfo, error) {
}
err = fuse.Unmount(cleanedMountPoint)
if err != nil {
- err1 := externalUnMount(cleanedMountPoint)
+ err1 := externalUnmount(cleanedMountPoint)
if err1 != nil {
errStr := fmt.Sprintf("UnMount error: %v", err)
log.Warn(errStr)
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 {