mountlib: windows fixes for drive letter and timing

This commit is contained in:
Nick Craig-Wood 2017-05-08 14:55:05 +01:00
parent 917ea6ac57
commit 6a8e4690d3

View file

@ -10,8 +10,10 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"runtime"
"strings" "strings"
"testing" "testing"
"time"
"github.com/ncw/rclone/cmd/mountlib" "github.com/ncw/rclone/cmd/mountlib"
"github.com/ncw/rclone/fs" "github.com/ncw/rclone/fs"
@ -102,10 +104,25 @@ func newRun() *Run {
log.Fatalf("Failed to open mkdir %q: %v", *RemoteName, err) log.Fatalf("Failed to open mkdir %q: %v", *RemoteName, err)
} }
if runtime.GOOS != "windows" {
r.mountPath, err = ioutil.TempDir("", "rclonefs-mount") r.mountPath, err = ioutil.TempDir("", "rclonefs-mount")
if err != nil { if err != nil {
log.Fatalf("Failed to create mount dir: %v", err) log.Fatalf("Failed to create mount dir: %v", err)
} }
} else {
// Find a free drive letter
drive := ""
for letter := 'E'; letter <= 'Z'; letter++ {
drive = string(letter) + ":"
_, err := os.Stat(drive + "\\")
if os.IsNotExist(err) {
goto found
}
}
log.Fatalf("Couldn't find free drive letter for test")
found:
r.mountPath = drive
}
// Mount it up // Mount it up
r.mount() r.mount()
@ -122,6 +139,9 @@ func (r *Run) mount() {
r.skip = true r.skip = true
} }
log.Printf("mount OK") log.Printf("mount OK")
if runtime.GOOS == "windows" {
time.Sleep(time.Second) // FIXME remove this when https://github.com/billziss-gh/cgofuse/issues/11 is fixed
}
} }
func (r *Run) umount() { func (r *Run) umount() {
@ -165,6 +185,10 @@ func (r *Run) Finalise() {
} }
func (r *Run) path(filepath string) string { func (r *Run) path(filepath string) string {
// return windows drive letter root as E:/
if filepath == "" && runtime.GOOS == "windows" {
return run.mountPath + "/"
}
return path.Join(run.mountPath, filepath) return path.Join(run.mountPath, filepath)
} }