mirror of
https://github.com/rclone/rclone
synced 2024-11-14 13:36:24 +01:00
vfs: [bugfix] Implement Name() method in WriteFileHandle and ReadFileHandle
Name() method was originally left out and defaulted to the base class which always returns empty. This trigerred incorrect behavior in serve nfs where it relied on the Name() of the interafce to figure out what file it was modifying. This method is copied from RWFileHandle struct. Added extra assert in the tests.
This commit is contained in:
parent
3337fe31c7
commit
23f8dea182
@ -484,6 +484,11 @@ func (fh *ReadFileHandle) Release() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Name returns the name of the file from the underlying Object.
|
||||
func (fh *ReadFileHandle) Name() string {
|
||||
return fh.file.String()
|
||||
}
|
||||
|
||||
// Size returns the size of the underlying file
|
||||
func (fh *ReadFileHandle) Size() int64 {
|
||||
fh.mu.Lock()
|
||||
|
@ -44,6 +44,9 @@ func TestReadFileHandleMethods(t *testing.T) {
|
||||
assert.Equal(t, "<nil *ReadFileHandle>", (*ReadFileHandle)(nil).String())
|
||||
assert.Equal(t, "<nil *ReadFileHandle.file>", new(ReadFileHandle).String())
|
||||
|
||||
// Name
|
||||
assert.Equal(t, "dir/file1", fh.Name())
|
||||
|
||||
// Node
|
||||
node := fh.Node()
|
||||
assert.Equal(t, "file1", node.Name())
|
||||
|
@ -346,6 +346,9 @@ func TestRWFileHandleWriteAt(t *testing.T) {
|
||||
return n
|
||||
}
|
||||
|
||||
// Name
|
||||
assert.Equal(t, "file1", fh.Name())
|
||||
|
||||
// Preconditions
|
||||
assert.Equal(t, int64(0), offset())
|
||||
assert.True(t, fh.opened)
|
||||
|
@ -322,3 +322,8 @@ func (fh *WriteFileHandle) ReadAt(p []byte, off int64) (n int, err error) {
|
||||
func (fh *WriteFileHandle) Sync() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name returns the name of the file from the underlying Object.
|
||||
func (fh *WriteFileHandle) Name() string {
|
||||
return fh.file.String()
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ func TestWriteFileHandleReadonly(t *testing.T) {
|
||||
}
|
||||
r, vfs, fh := writeHandleCreate(t)
|
||||
|
||||
// Name
|
||||
assert.Equal(t, "file1", fh.Name())
|
||||
|
||||
// Write a file, so underlying remote will be created
|
||||
_, err := fh.Write([]byte("hello"))
|
||||
assert.NoError(t, err)
|
||||
|
Loading…
Reference in New Issue
Block a user