diff --git a/fuse/handler.go b/fuse/handler.go index 33d4f62..1a77001 100644 --- a/fuse/handler.go +++ b/fuse/handler.go @@ -30,8 +30,11 @@ func (s *Handler) Mount(fss map[string]fs.Filesystem) error { if runtime.GOOS == "windows" { folder = filepath.Dir(s.path) } - if err := os.MkdirAll(folder, 0744); err != nil && !os.IsExist(err) { - return err + + if filepath.VolumeName(folder) == "" { + if err := os.MkdirAll(folder, 0744); err != nil && !os.IsExist(err) { + return err + } } cfs, err := fs.NewContainerFs(fss) @@ -57,7 +60,7 @@ func (s *Handler) Mount(fss map[string]fs.Filesystem) error { s.host = host - log.Info().Str("path", folder).Msg("starting FUSE mount") + log.Info().Str("path", s.path).Msg("starting FUSE mount") return nil } diff --git a/fuse/mount_test.go b/fuse/mount_test.go new file mode 100644 index 0000000..40485bb --- /dev/null +++ b/fuse/mount_test.go @@ -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()) +}