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.
This commit is contained in:
Felix Lange 2017-05-30 11:21:59 +02:00
parent 693d9ccbfb
commit 50c18e6eb8
2 changed files with 20 additions and 35 deletions

View File

@ -19,18 +19,19 @@
package fuse package fuse
import ( import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/api"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
"time" "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 ( var (
@ -203,7 +204,7 @@ func (self *SwarmFS) Unmount(mountpoint string) (*MountInfo, error) {
} }
err = fuse.Unmount(cleanedMountPoint) err = fuse.Unmount(cleanedMountPoint)
if err != nil { if err != nil {
err1 := externalUnMount(cleanedMountPoint) err1 := externalUnmount(cleanedMountPoint)
if err1 != nil { if err1 != nil {
errStr := fmt.Sprintf("UnMount error: %v", err) errStr := fmt.Sprintf("UnMount error: %v", err)
log.Warn(errStr) log.Warn(errStr)

View File

@ -19,47 +19,31 @@
package fuse package fuse
import ( import (
"context"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/log"
"os/exec" "os/exec"
"runtime" "runtime"
"time"
"github.com/ethereum/go-ethereum/log"
) )
func externalUnMount(mountPoint string) error { func externalUnmount(mountPoint string) error {
ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout)
var cmd *exec.Cmd 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 { switch runtime.GOOS {
case "darwin": case "darwin":
cmd = exec.Command("/usr/bin/diskutil", "umount", "force", mountPoint) return exec.CommandContext(ctx, "diskutil", "umount", "force", mountPoint).Run()
case "linux": case "linux":
cmd = exec.Command("fusermount", "-u", mountPoint) return exec.CommandContext(ctx, "fusermount", "-u", mountPoint).Run()
default: default:
return fmt.Errorf("unmount: unimplemented") 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 { func addFileToSwarm(sf *SwarmFile, content []byte, size int) error {