mirror of
https://github.com/rclone/rclone
synced 2024-11-10 08:08:35 +01:00
vfs: write 0 bytes when flushing unwritten handles to avoid race conditions in FUSE - fixes #1181
This commit is contained in:
parent
b33e3f779c
commit
846bbef1e9
@ -231,9 +231,9 @@ func (fh *WriteFileHandle) Flush() error {
|
||||
// If Write hasn't been called then ignore the Flush - Release
|
||||
// will pick it up
|
||||
if !fh.writeCalled {
|
||||
fs.Debugf(fh.remote, "WriteFileHandle.Flush ignoring flush on unwritten handle")
|
||||
return nil
|
||||
|
||||
fs.Debugf(fh.remote, "WriteFileHandle.Flush unwritten handle, writing 0 bytes to avoid race conditions")
|
||||
_, err := fh.writeAt([]byte{}, fh.offset)
|
||||
return err
|
||||
}
|
||||
err := fh.close()
|
||||
if err != nil {
|
||||
|
@ -168,12 +168,15 @@ func TestWriteFileHandleWriteAt(t *testing.T) {
|
||||
func TestWriteFileHandleFlush(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
_, fh := writeHandleCreate(t, r)
|
||||
vfs, fh := writeHandleCreate(t, r)
|
||||
|
||||
// Check Flush does nothing if write not called
|
||||
// Check Flush already creates file for unwritten handles, without closing it
|
||||
err := fh.Flush()
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, fh.closed)
|
||||
root, err := vfs.Root()
|
||||
assert.NoError(t, err)
|
||||
checkListing(t, root, []string{"file1,0,false"})
|
||||
|
||||
// Write some data
|
||||
n, err := fh.Write([]byte("hello"))
|
||||
@ -189,6 +192,11 @@ func TestWriteFileHandleFlush(t *testing.T) {
|
||||
err = fh.Flush()
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, fh.closed)
|
||||
|
||||
// Check file was written properly
|
||||
root, err = vfs.Root()
|
||||
assert.NoError(t, err)
|
||||
checkListing(t, root, []string{"file1,5,false"})
|
||||
}
|
||||
|
||||
func TestWriteFileHandleRelease(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user