mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 14:51:48 +08:00
vfs: stop reading File members from outside file.go
This also fixes locking for ReadFileHandle and WriteFileHandle accessing File members
This commit is contained in:
parent
268fcbb973
commit
238f26cc90
|
@ -607,6 +607,13 @@ func (f *File) VFS() *VFS {
|
||||||
return f.d.vfs
|
return f.d.vfs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fs returns the underlying Fs for the file
|
||||||
|
func (f *File) Fs() fs.Fs {
|
||||||
|
f.mu.RLock()
|
||||||
|
defer f.mu.RUnlock()
|
||||||
|
return f.d.f
|
||||||
|
}
|
||||||
|
|
||||||
// Open a file according to the flags provided
|
// Open a file according to the flags provided
|
||||||
//
|
//
|
||||||
// O_RDONLY open the file read-only.
|
// O_RDONLY open the file read-only.
|
||||||
|
|
10
vfs/read.go
10
vfs/read.go
|
@ -47,7 +47,7 @@ func newReadFileHandle(f *File) (*ReadFileHandle, error) {
|
||||||
var mhash *hash.MultiHasher
|
var mhash *hash.MultiHasher
|
||||||
var err error
|
var err error
|
||||||
o := f.getObject()
|
o := f.getObject()
|
||||||
if !f.d.vfs.Opt.NoChecksum {
|
if !f.VFS().Opt.NoChecksum {
|
||||||
hashes := hash.NewHashSet(o.Fs().Hashes().GetOne()) // just pick one hash
|
hashes := hash.NewHashSet(o.Fs().Hashes().GetOne()) // just pick one hash
|
||||||
mhash, err = hash.NewMultiHasherTypes(hashes)
|
mhash, err = hash.NewMultiHasherTypes(hashes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,7 +57,7 @@ func newReadFileHandle(f *File) (*ReadFileHandle, error) {
|
||||||
|
|
||||||
fh := &ReadFileHandle{
|
fh := &ReadFileHandle{
|
||||||
remote: o.Remote(),
|
remote: o.Remote(),
|
||||||
noSeek: f.d.vfs.Opt.NoSeek,
|
noSeek: f.VFS().Opt.NoSeek,
|
||||||
file: f,
|
file: f,
|
||||||
hash: mhash,
|
hash: mhash,
|
||||||
size: nonNegative(o.Size()),
|
size: nonNegative(o.Size()),
|
||||||
|
@ -74,7 +74,7 @@ func (fh *ReadFileHandle) openPending() (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
o := fh.file.getObject()
|
o := fh.file.getObject()
|
||||||
r, err := chunkedreader.New(context.TODO(), o, int64(fh.file.d.vfs.Opt.ChunkSize), int64(fh.file.d.vfs.Opt.ChunkSizeLimit)).Open()
|
r, err := chunkedreader.New(context.TODO(), o, int64(fh.file.VFS().Opt.ChunkSize), int64(fh.file.VFS().Opt.ChunkSizeLimit)).Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ func (fh *ReadFileHandle) seek(offset int64, reopen bool) (err error) {
|
||||||
}
|
}
|
||||||
// re-open with a seek
|
// re-open with a seek
|
||||||
o := fh.file.getObject()
|
o := fh.file.getObject()
|
||||||
r = chunkedreader.New(context.TODO(), o, int64(fh.file.d.vfs.Opt.ChunkSize), int64(fh.file.d.vfs.Opt.ChunkSizeLimit))
|
r = chunkedreader.New(context.TODO(), o, int64(fh.file.VFS().Opt.ChunkSize), int64(fh.file.VFS().Opt.ChunkSizeLimit))
|
||||||
_, err := r.Seek(offset, 0)
|
_, err := r.Seek(offset, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(fh.remote, "ReadFileHandle.Read seek failed: %v", err)
|
fs.Debugf(fh.remote, "ReadFileHandle.Read seek failed: %v", err)
|
||||||
|
@ -235,7 +235,7 @@ func (fh *ReadFileHandle) readAt(p []byte, off int64) (n int, err error) {
|
||||||
// The default time here was made by finding the
|
// The default time here was made by finding the
|
||||||
// smallest when mounting a local backend that didn't
|
// smallest when mounting a local backend that didn't
|
||||||
// cause seeks.
|
// cause seeks.
|
||||||
maxWait := fh.file.d.vfs.Opt.ReadWait
|
maxWait := fh.file.VFS().Opt.ReadWait
|
||||||
timeout := time.NewTimer(maxWait)
|
timeout := time.NewTimer(maxWait)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
abort := int32(0)
|
abort := int32(0)
|
||||||
|
|
|
@ -69,7 +69,7 @@ func (fh *WriteFileHandle) openPending() (err error) {
|
||||||
pipeReader, fh.pipeWriter = io.Pipe()
|
pipeReader, fh.pipeWriter = io.Pipe()
|
||||||
go func() {
|
go func() {
|
||||||
// NB Rcat deals with Stats.Transferring etc
|
// NB Rcat deals with Stats.Transferring etc
|
||||||
o, err := operations.Rcat(context.TODO(), fh.file.d.f, fh.remote, pipeReader, time.Now())
|
o, err := operations.Rcat(context.TODO(), fh.file.Fs(), fh.remote, pipeReader, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(fh.remote, "WriteFileHandle.New Rcat failed: %v", err)
|
fs.Errorf(fh.remote, "WriteFileHandle.New Rcat failed: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (fh *WriteFileHandle) openPending() (err error) {
|
||||||
}()
|
}()
|
||||||
fh.file.setSize(0)
|
fh.file.setSize(0)
|
||||||
fh.truncated = true
|
fh.truncated = true
|
||||||
fh.file.d.addObject(fh.file) // make sure the directory has this object in it now
|
fh.file.Dir().addObject(fh.file) // make sure the directory has this object in it now
|
||||||
fh.opened = true
|
fh.opened = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func (fh *WriteFileHandle) writeAt(p []byte, off int64) (n int, err error) {
|
||||||
}
|
}
|
||||||
if fh.offset != off {
|
if fh.offset != off {
|
||||||
// Set a background timer so we don't wait forever
|
// Set a background timer so we don't wait forever
|
||||||
maxWait := fh.file.d.vfs.Opt.WriteWait
|
maxWait := fh.file.VFS().Opt.WriteWait
|
||||||
timeout := time.NewTimer(maxWait)
|
timeout := time.NewTimer(maxWait)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
abort := int32(0)
|
abort := int32(0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user