forked from TrueCloudLab/rclone
vfs: rename Fsync to Sync and implement Sync on Node and Handle
This commit is contained in:
parent
eb3415db50
commit
b4083b4371
10 changed files with 40 additions and 10 deletions
|
@ -174,7 +174,7 @@ var _ fusefs.NodeFsyncer = (*Dir)(nil)
|
||||||
// Fsync the directory
|
// Fsync the directory
|
||||||
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
|
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
|
||||||
defer fs.Trace(d, "")("err=%v", &err)
|
defer fs.Trace(d, "")("err=%v", &err)
|
||||||
err = d.Dir.Fsync()
|
err = d.Dir.Sync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return translateError(err)
|
return translateError(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,10 +498,10 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fsync the directory
|
// Sync the directory
|
||||||
//
|
//
|
||||||
// Note that we don't do anything except return OK
|
// Note that we don't do anything except return OK
|
||||||
func (d *Dir) Fsync() error {
|
func (d *Dir) Sync() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ func TestDirMethods(t *testing.T) {
|
||||||
// Size
|
// Size
|
||||||
assert.Equal(t, int64(0), dir.Size())
|
assert.Equal(t, int64(0), dir.Size())
|
||||||
|
|
||||||
// Fsync
|
// Sync
|
||||||
assert.NoError(t, dir.Fsync())
|
assert.NoError(t, dir.Sync())
|
||||||
|
|
||||||
// DirEntry
|
// DirEntry
|
||||||
assert.Equal(t, dir.entry, dir.DirEntry())
|
assert.Equal(t, dir.entry, dir.DirEntry())
|
||||||
|
|
|
@ -293,10 +293,10 @@ func (f *File) OpenRW(flags int) (fh *RWFileHandle, err error) {
|
||||||
return fh, nil
|
return fh, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fsync the file
|
// Sync the file
|
||||||
//
|
//
|
||||||
// Note that we don't do anything except return OK
|
// Note that we don't do anything except return OK
|
||||||
func (f *File) Fsync() error {
|
func (f *File) Sync() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,8 @@ func TestFileMethods(t *testing.T) {
|
||||||
// Size
|
// Size
|
||||||
assert.Equal(t, int64(14), file.Size())
|
assert.Equal(t, int64(14), file.Size())
|
||||||
|
|
||||||
// Fsync
|
// Sync
|
||||||
assert.NoError(t, file.Fsync())
|
assert.NoError(t, file.Sync())
|
||||||
|
|
||||||
// DirEntry
|
// DirEntry
|
||||||
assert.Equal(t, file.o, file.DirEntry())
|
assert.Equal(t, file.o, file.DirEntry())
|
||||||
|
|
|
@ -408,3 +408,18 @@ func (fh *RWFileHandle) Truncate(size int64) (err error) {
|
||||||
fh.file.setSize(size)
|
fh.file.setSize(size)
|
||||||
return fh.File.Truncate(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()
|
||||||
|
}
|
||||||
|
|
|
@ -78,6 +78,10 @@ func TestRWFileHandleMethodsRead(t *testing.T) {
|
||||||
_, err := fh.Read(buf)
|
_, err := fh.Read(buf)
|
||||||
assert.Equal(t, io.EOF, err)
|
assert.Equal(t, io.EOF, err)
|
||||||
|
|
||||||
|
// Sync
|
||||||
|
err = fh.Sync()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Stat
|
// Stat
|
||||||
var fi os.FileInfo
|
var fi os.FileInfo
|
||||||
fi, err = fh.Stat()
|
fi, err = fh.Stat()
|
||||||
|
|
|
@ -54,7 +54,7 @@ type Node interface {
|
||||||
IsFile() bool
|
IsFile() bool
|
||||||
Inode() uint64
|
Inode() uint64
|
||||||
SetModTime(modTime time.Time) error
|
SetModTime(modTime time.Time) error
|
||||||
Fsync() error
|
Sync() error
|
||||||
Remove() error
|
Remove() error
|
||||||
RemoveAll() error
|
RemoveAll() error
|
||||||
DirEntry() fs.DirEntry
|
DirEntry() fs.DirEntry
|
||||||
|
|
|
@ -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")
|
fs.Errorf(fh.remote, "ReadAt: Can't read and write to file without cache")
|
||||||
return 0, EPERM
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -65,6 +65,10 @@ func TestWriteFileHandleMethods(t *testing.T) {
|
||||||
_, err = fh.ReadAt(buf, 0)
|
_, err = fh.ReadAt(buf, 0)
|
||||||
assert.Equal(t, EPERM, err)
|
assert.Equal(t, EPERM, err)
|
||||||
|
|
||||||
|
// Sync
|
||||||
|
err = fh.Sync()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Close
|
// Close
|
||||||
assert.NoError(t, fh.Close())
|
assert.NoError(t, fh.Close())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue