vfs: rename Fsync to Sync and implement Sync on Node and Handle

This commit is contained in:
Nick Craig-Wood 2017-11-18 15:48:49 +00:00
parent eb3415db50
commit b4083b4371
10 changed files with 40 additions and 10 deletions

View File

@ -174,7 +174,7 @@ var _ fusefs.NodeFsyncer = (*Dir)(nil)
// Fsync the directory
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
defer fs.Trace(d, "")("err=%v", &err)
err = d.Dir.Fsync()
err = d.Dir.Sync()
if err != nil {
return translateError(err)
}

View File

@ -498,10 +498,10 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
return nil
}
// Fsync the directory
// Sync the directory
//
// Note that we don't do anything except return OK
func (d *Dir) Fsync() error {
func (d *Dir) Sync() error {
return nil
}

View File

@ -64,8 +64,8 @@ func TestDirMethods(t *testing.T) {
// Size
assert.Equal(t, int64(0), dir.Size())
// Fsync
assert.NoError(t, dir.Fsync())
// Sync
assert.NoError(t, dir.Sync())
// DirEntry
assert.Equal(t, dir.entry, dir.DirEntry())

View File

@ -293,10 +293,10 @@ func (f *File) OpenRW(flags int) (fh *RWFileHandle, err error) {
return fh, nil
}
// Fsync the file
// Sync the file
//
// Note that we don't do anything except return OK
func (f *File) Fsync() error {
func (f *File) Sync() error {
return nil
}

View File

@ -62,8 +62,8 @@ func TestFileMethods(t *testing.T) {
// Size
assert.Equal(t, int64(14), file.Size())
// Fsync
assert.NoError(t, file.Fsync())
// Sync
assert.NoError(t, file.Sync())
// DirEntry
assert.Equal(t, file.o, file.DirEntry())

View File

@ -408,3 +408,18 @@ func (fh *RWFileHandle) Truncate(size int64) (err error) {
fh.file.setSize(size)
return fh.File.Truncate(size)
}
// Sync commits the current contents of the file to stable storage. Typically,
// this means flushing the file system's in-memory copy of recently written
// data to disk.
func (fh *RWFileHandle) Sync() error {
fh.mu.Lock()
defer fh.mu.Unlock()
if fh.closed {
return ECLOSED
}
if !fh.opened {
return nil
}
return fh.File.Sync()
}

View File

@ -78,6 +78,10 @@ func TestRWFileHandleMethodsRead(t *testing.T) {
_, err := fh.Read(buf)
assert.Equal(t, io.EOF, err)
// Sync
err = fh.Sync()
assert.NoError(t, err)
// Stat
var fi os.FileInfo
fi, err = fh.Stat()

View File

@ -54,7 +54,7 @@ type Node interface {
IsFile() bool
Inode() uint64
SetModTime(modTime time.Time) error
Fsync() error
Sync() error
Remove() error
RemoveAll() error
DirEntry() fs.DirEntry

View File

@ -264,3 +264,10 @@ func (fh *WriteFileHandle) ReadAt(p []byte, off int64) (n int, err error) {
fs.Errorf(fh.remote, "ReadAt: Can't read and write to file without cache")
return 0, EPERM
}
// Sync commits the current contents of the file to stable storage. Typically,
// this means flushing the file system's in-memory copy of recently written
// data to disk.
func (fh *WriteFileHandle) Sync() error {
return nil
}

View File

@ -65,6 +65,10 @@ func TestWriteFileHandleMethods(t *testing.T) {
_, err = fh.ReadAt(buf, 0)
assert.Equal(t, EPERM, err)
// Sync
err = fh.Sync()
assert.NoError(t, err)
// Close
assert.NoError(t, fh.Close())