Skip to content

Commit

Permalink
Make TestReadDirSlurpContinuation work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Jun 19, 2023
1 parent 38bb898 commit 25b3ba4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/goofys_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ package internal
import (
"bytes"
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"syscall"
"time"

Expand Down Expand Up @@ -163,22 +165,23 @@ func (s *GoofysTest) TestReadDirSlurpContinuation(t *C) {
t.Assert(err, IsNil)
}
// Sync the whole filesystem
fh, err := os.Open(mountPoint)
t.Assert(err, IsNil)
err = fh.Sync()
t.Assert(err, IsNil)
err = fh.Close()
err := FsyncDir(mountPoint)
t.Assert(err, IsNil)
// Unmount
s.umount(t, mountPoint)

// Mount again
s.mount(t, mountPoint)
// Check that `find` returns all files to check that slurp works correctly with the continuation
c := exec.Command("/bin/bash", "-c", "find "+mountPoint+"/slurpc -type f | wc -l")
out, err := c.CombinedOutput()
t.Assert(err, IsNil)
t.Assert(string(out), Equals, "2003\n")
// Check that all files are present to check that slurp works correctly with the continuation
count := 0
filepath.Walk(mountPoint+"/slurpc", func(path string, info fs.FileInfo, err error) error {
t.Assert(err, IsNil)
if !info.IsDir() {
count++
}
return nil
})
t.Assert(count, Equals, 2003)
}

func (s *GoofysTest) writeSeekWriteFuse(t *C, file string, fh *os.File, first string, second string, third string) {
Expand Down
13 changes: 13 additions & 0 deletions internal/goofys_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ func (s *GoofysTest) umount(t *C, mountPoint string) {
os.Remove(mountPoint)
}

func FsyncDir(dir string) error {
fh, err := os.Open(dir)
if err != nil {
return err
}
err = fh.Sync()
if err != nil {
fh.Close()
return err
}
return fh.Close()
}

func (s *GoofysTest) SetUpSuite(t *C) {
s.tmp = os.Getenv("TMPDIR")
if s.tmp == "" {
Expand Down
45 changes: 45 additions & 0 deletions internal/goofys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,22 @@ func (fs *GoofysWin) Create(path string, flags int, mode uint32) (ret int, fhId
return mapWinError(err), 0
}

if fs.flags.FlushFilename != "" && child == fs.flags.FlushFilename {
err = fs.SyncFS(parent)
if err == nil {
err = syscall.ENOENT
}
return mapWinError(err), 0
}

if fs.flags.RefreshFilename != "" && child == fs.flags.RefreshFilename {
err = fs.RefreshInodeCache(parent)
if err == nil {
err = syscall.ENOENT
}
return mapWinError(err), 0
}

inode, fh, err := parent.Create(child)
if err != nil {
return mapWinError(err), 0
Expand All @@ -428,6 +444,11 @@ func (fs *GoofysWin) Create(path string, flags int, mode uint32) (ret int, fhId
return 0, uint64(handleID)
}

func endsWith(path, part string) bool {
ld := len(path)-len(part)
return len(part) > 0 && ld >= 0 && (ld == 0 || path[ld-1] == '/') && path[ld:] == part
}

// Open opens a file.
// The flags are a combination of the fuse.O_* constants.
func (fs *GoofysWin) Open(path string, flags int) (ret int, fhId uint64) {
Expand All @@ -442,6 +463,30 @@ func (fs *GoofysWin) Open(path string, flags int) (ret int, fhId uint64) {

inode, err := fs.LookupPath(path)
if err != nil {
if endsWith(path, fs.flags.FlushFilename) {
parent, _, err := fs.LookupParent(path)
if err != nil {
return mapWinError(err), 0
}
if err == nil {
err = fs.SyncFS(parent)
}
if err == nil {
err = syscall.ENOENT
}
}
if endsWith(path, fs.flags.RefreshFilename) {
parent, _, err := fs.LookupParent(path)
if err != nil {
return mapWinError(err), 0
}
if err == nil {
err = fs.RefreshInodeCache(parent)
}
if err == nil {
err = syscall.ENOENT
}
}
return mapWinError(err), 0
}

Expand Down
13 changes: 13 additions & 0 deletions internal/goofys_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package internal

import (
"errors"
"os"
"syscall"
"time"
. "gopkg.in/check.v1"
)
Expand Down Expand Up @@ -54,3 +56,14 @@ func (s *GoofysTest) umount(t *C, mountPoint string) {
s.mfs.Unmount()
s.mfs = nil
}

func FsyncDir(dir string) error {
fh, err := os.Create(dir+"/.fsyncdir")
if errors.Is(err, syscall.ENOENT) {
return nil
}
if err == nil {
fh.Close()
}
return err
}

0 comments on commit 25b3ba4

Please sign in to comment.