From 5bf3c5e2a4f9bfdd76921d539736e23982b36509 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 19 Jun 2023 18:09:49 +0300 Subject: [PATCH] Renaming an open file does not work on Windows --- internal/goofys_fs_test.go | 88 ------------------------------------ internal/goofys_unix_test.go | 88 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/internal/goofys_fs_test.go b/internal/goofys_fs_test.go index c2d7fbfb..398047b5 100644 --- a/internal/goofys_fs_test.go +++ b/internal/goofys_fs_test.go @@ -134,94 +134,6 @@ func (s *GoofysTest) TestWriteSyncWriteFuse(t *C) { t.Assert(err, IsNil) } -func (s *GoofysTest) TestCreateRenameBeforeCloseFuse(t *C) { - if s.azurite { - // Azurite returns 400 when copy source doesn't exist - // https://github.com/Azure/Azurite/issues/219 - // so our code to ignore ENOENT fails - t.Skip("https://github.com/Azure/Azurite/issues/219") - } - - mountPoint := s.tmp + "/mnt" + s.fs.bucket - - s.mount(t, mountPoint) - defer s.umount(t, mountPoint) - - from := mountPoint + "/newfile" - to := mountPoint + "/newfile2" - - fh, err := os.Create(from) - t.Assert(err, IsNil) - defer func() { - // close the file if the test failed so we can unmount - if fh != nil { - fh.Close() - } - }() - - _, err = fh.WriteString("hello world") - t.Assert(err, IsNil) - - err = os.Rename(from, to) - t.Assert(err, IsNil) - - err = fh.Close() - t.Assert(err, IsNil) - fh = nil - - _, err = os.Stat(from) - t.Assert(err, NotNil) - pathErr, ok := err.(*os.PathError) - t.Assert(ok, Equals, true) - t.Assert(pathErr.Err, Equals, syscall.ENOENT) - - content, err := ioutil.ReadFile(to) - t.Assert(err, IsNil) - t.Assert(string(content), Equals, "hello world") -} - -func (s *GoofysTest) TestRenameBeforeCloseFuse(t *C) { - mountPoint := s.tmp + "/mnt" + s.fs.bucket - - s.mount(t, mountPoint) - defer s.umount(t, mountPoint) - - from := mountPoint + "/newfile" - to := mountPoint + "/newfile2" - - err := ioutil.WriteFile(from, []byte(""), 0600) - t.Assert(err, IsNil) - - fh, err := os.OpenFile(from, os.O_WRONLY, 0600) - t.Assert(err, IsNil) - defer func() { - // close the file if the test failed so we can unmount - if fh != nil { - fh.Close() - } - }() - - _, err = fh.WriteString("hello world") - t.Assert(err, IsNil) - - err = os.Rename(from, to) - t.Assert(err, IsNil) - - err = fh.Close() - t.Assert(err, IsNil) - fh = nil - - _, err = os.Stat(from) - t.Assert(err, NotNil) - pathErr, ok := err.(*os.PathError) - t.Assert(ok, Equals, true) - t.Assert(pathErr.Err, Equals, syscall.ENOENT) - - content, err := ioutil.ReadFile(to) - t.Assert(err, IsNil) - t.Assert(string(content), Equals, "hello world") -} - func (s *GoofysTest) TestReadDirSlurpContinuation(t *C) { if _, ok := s.cloud.Delegate().(*S3Backend); !ok { t.Skip("only for S3") diff --git a/internal/goofys_unix_test.go b/internal/goofys_unix_test.go index 56ecc7be..a1c16484 100644 --- a/internal/goofys_unix_test.go +++ b/internal/goofys_unix_test.go @@ -351,6 +351,94 @@ func (s *GoofysTest) TestPythonCopyTree(t *C) { mountPoint) } +func (s *GoofysTest) TestCreateRenameBeforeCloseFuse(t *C) { + if s.azurite { + // Azurite returns 400 when copy source doesn't exist + // https://github.com/Azure/Azurite/issues/219 + // so our code to ignore ENOENT fails + t.Skip("https://github.com/Azure/Azurite/issues/219") + } + + mountPoint := s.tmp + "/mnt" + s.fs.bucket + + s.mount(t, mountPoint) + defer s.umount(t, mountPoint) + + from := mountPoint + "/newfile" + to := mountPoint + "/newfile2" + + fh, err := os.Create(from) + t.Assert(err, IsNil) + defer func() { + // close the file if the test failed so we can unmount + if fh != nil { + fh.Close() + } + }() + + _, err = fh.WriteString("hello world") + t.Assert(err, IsNil) + + err = os.Rename(from, to) + t.Assert(err, IsNil) + + err = fh.Close() + t.Assert(err, IsNil) + fh = nil + + _, err = os.Stat(from) + t.Assert(err, NotNil) + pathErr, ok := err.(*os.PathError) + t.Assert(ok, Equals, true) + t.Assert(pathErr.Err, Equals, syscall.ENOENT) + + content, err := ioutil.ReadFile(to) + t.Assert(err, IsNil) + t.Assert(string(content), Equals, "hello world") +} + +func (s *GoofysTest) TestRenameBeforeCloseFuse(t *C) { + mountPoint := s.tmp + "/mnt" + s.fs.bucket + + s.mount(t, mountPoint) + defer s.umount(t, mountPoint) + + from := mountPoint + "/newfile" + to := mountPoint + "/newfile2" + + err := ioutil.WriteFile(from, []byte(""), 0600) + t.Assert(err, IsNil) + + fh, err := os.OpenFile(from, os.O_WRONLY, 0600) + t.Assert(err, IsNil) + defer func() { + // close the file if the test failed so we can unmount + if fh != nil { + fh.Close() + } + }() + + _, err = fh.WriteString("hello world") + t.Assert(err, IsNil) + + err = os.Rename(from, to) + t.Assert(err, IsNil) + + err = fh.Close() + t.Assert(err, IsNil) + fh = nil + + _, err = os.Stat(from) + t.Assert(err, NotNil) + pathErr, ok := err.(*os.PathError) + t.Assert(ok, Equals, true) + t.Assert(pathErr.Err, Equals, syscall.ENOENT) + + content, err := ioutil.ReadFile(to) + t.Assert(err, IsNil) + t.Assert(string(content), Equals, "hello world") +} + func containsFile(dir, wantedFile string) bool { files, err := os.ReadDir(dir) if err != nil {