fs: fix bug preventing Finder from working.

Apparently we need to update the node's size after a write on a filehandle.
Finder stats it (the node, not the handle) while writing and complains if it's
not the right size.

Change-Id: Ie3e98328a182a4bbb3230c5190e1d57d0d3fb075
This commit is contained in:
Brad Fitzpatrick 2013-07-22 09:52:48 -07:00
parent f8f71e0d77
commit f0edcaa7d4
2 changed files with 21 additions and 6 deletions

View File

@ -175,7 +175,7 @@ func TestMutable(t *testing.T) {
condSkip(t)
cammountTest(t, func(env *mountEnv) {
rootDir := filepath.Join(env.mountPoint, "roots", "r")
if err := os.Mkdir(rootDir, 0700); err != nil {
if err := os.MkdirAll(rootDir, 0755); err != nil {
t.Fatalf("Failed to make roots/r dir: %v", err)
}
fi, err := os.Stat(rootDir)
@ -239,13 +239,16 @@ func TestMutable(t *testing.T) {
})
}
func brokenTest(t *testing.T) {
if v, _ := strconv.ParseBool(os.Getenv("RUN_BROKEN_TESTS")); !v {
t.Skipf("Skipping broken tests without RUN_BROKEN_TESTS=1")
}
}
func TestFinderCopy(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skipf("Skipping Darwin-specific test.")
}
if v, _ := strconv.ParseBool(os.Getenv("RUN_BROKEN_TESTS")); !v {
t.Skipf("Skipping broken tests without RUN_BROKEN_TESTS=1")
}
condSkip(t)
cammountTest(t, func(env *mountEnv) {
f, err := ioutil.TempFile("", "finder-copy-file")
@ -261,7 +264,7 @@ func TestFinderCopy(t *testing.T) {
t.Fatal(err)
}
destDir := filepath.Join(env.mountPoint, "roots", "r")
if err := os.Mkdir(destDir, 0755); err != nil {
if err := os.MkdirAll(destDir, 0755); err != nil {
t.Fatal(err)
}
cmd := exec.Command("osascript")
@ -270,7 +273,6 @@ tell application "Finder"
copy file POSIX file %q to folder POSIX file %q
end tell
`, f.Name(), destDir)
log.Printf("Running AppleScript:\n%s", script)
cmd.Stdin = strings.NewReader(script)
if out, err := cmd.CombinedOutput(); err != nil {
@ -284,6 +286,9 @@ end tell
if err != nil {
t.Errorf("Stat = %v, %v", fi, err)
}
if fi.Size() != int64(len(want)) {
t.Errorf("Dest stat size = %d; want %d", fi.Size(), len(want))
}
slurp, err := ioutil.ReadFile(destFile)
if err != nil {
t.Fatalf("ReadFile: %v", err)

View File

@ -353,6 +353,15 @@ func (n *mutFile) setContent(br *blobref.BlobRef, size int64) error {
return err
}
func (n *mutFile) setSizeAtLeast(size int64) {
n.mu.Lock()
defer n.mu.Unlock()
log.Printf("mutFile.setSizeAtLeast(%d). old size = %d", size, n.size)
if size > n.size {
n.size = size
}
}
// Empirically:
// open for read: req.Flags == 0
// open for append: req.Flags == 1
@ -481,6 +490,7 @@ func (h *mutFileHandle) Write(req *fuse.WriteRequest, res *fuse.WriteResponse, i
return fuse.EIO
}
res.Size = n
h.f.setSizeAtLeast(req.Offset + int64(n))
return nil
}