mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:32:29 +08:00
vfs: don't open the file when using a RW handle for a null Seek
Background: cmd/mount/file.go Open() function does a Seek(0, 1) to see if the file handle is seekable to set a FUSE hint. Before this change the file was downloaded before it needed to be which was inefficient (and broke beta.rclone.org because HEAD requests caused downloads!).
This commit is contained in:
parent
1383df4f58
commit
9252224d82
|
@ -401,6 +401,9 @@ func (fh *RWFileHandle) Seek(offset int64, whence int) (ret int64, err error) {
|
|||
if fh.closed {
|
||||
return 0, ECLOSED
|
||||
}
|
||||
if !fh.opened && offset == 0 && whence != 2 {
|
||||
return 0, nil
|
||||
}
|
||||
if err = fh.openPending(false); err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
|
|
@ -110,10 +110,22 @@ func TestRWFileHandleSeek(t *testing.T) {
|
|||
vfs, fh := rwHandleCreateReadOnly(t, r)
|
||||
defer cleanup(t, r, vfs)
|
||||
|
||||
assert.Equal(t, fh.opened, false)
|
||||
|
||||
// Check null seeks don't open the file
|
||||
n, err := fh.Seek(0, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(0), n)
|
||||
assert.Equal(t, fh.opened, false)
|
||||
n, err = fh.Seek(0, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(0), n)
|
||||
assert.Equal(t, fh.opened, false)
|
||||
|
||||
assert.Equal(t, "0", rwReadString(t, fh, 1))
|
||||
|
||||
// 0 means relative to the origin of the file,
|
||||
n, err := fh.Seek(5, 0)
|
||||
n, err = fh.Seek(5, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(5), n)
|
||||
assert.Equal(t, "5", rwReadString(t, fh, 1))
|
||||
|
|
Loading…
Reference in New Issue
Block a user