Allow Drive Letters on mounts for windows (#115)
This commit is contained in:
parent
762feadfc4
commit
4b29ce6dc1
2 changed files with 74 additions and 3 deletions
|
@ -30,9 +30,12 @@ func (s *Handler) Mount(fss map[string]fs.Filesystem) error {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
folder = filepath.Dir(s.path)
|
folder = filepath.Dir(s.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filepath.VolumeName(folder) == "" {
|
||||||
if err := os.MkdirAll(folder, 0744); err != nil && !os.IsExist(err) {
|
if err := os.MkdirAll(folder, 0744); err != nil && !os.IsExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cfs, err := fs.NewContainerFs(fss)
|
cfs, err := fs.NewContainerFs(fss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,7 +60,7 @@ func (s *Handler) Mount(fss map[string]fs.Filesystem) error {
|
||||||
|
|
||||||
s.host = host
|
s.host = host
|
||||||
|
|
||||||
log.Info().Str("path", folder).Msg("starting FUSE mount")
|
log.Info().Str("path", s.path).Msg("starting FUSE mount")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
68
fuse/mount_test.go
Normal file
68
fuse/mount_test.go
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package fuse
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/distribyted/distribyted/fs"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHandler(t *testing.T) {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
t.Skip("test for windows only")
|
||||||
|
}
|
||||||
|
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
p := "./testmnt"
|
||||||
|
|
||||||
|
h := NewHandler(false, p)
|
||||||
|
|
||||||
|
mem := fs.NewMemory()
|
||||||
|
|
||||||
|
err := mem.Storage.Add(fs.NewMemoryFile([]byte("test")), "/test.txt")
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
err = h.Mount(map[string]fs.Filesystem{"/mem": mem})
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
|
fi, err := os.Stat(filepath.Join(p, "mem", "test.txt"))
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
require.False(fi.IsDir())
|
||||||
|
require.Equal(int64(4), fi.Size())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHandlerDriveLetter(t *testing.T) {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
t.Skip("test for windows only")
|
||||||
|
}
|
||||||
|
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
p := "Z:"
|
||||||
|
|
||||||
|
h := NewHandler(false, p)
|
||||||
|
|
||||||
|
mem := fs.NewMemory()
|
||||||
|
|
||||||
|
err := mem.Storage.Add(fs.NewMemoryFile([]byte("test")), "/test.txt")
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
err = h.Mount(map[string]fs.Filesystem{"/mem": mem})
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
|
fi, err := os.Stat(filepath.Join(p, "mem", "test.txt"))
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
require.False(fi.IsDir())
|
||||||
|
require.Equal(int64(4), fi.Size())
|
||||||
|
}
|
Loading…
Reference in a new issue