Add context propagation to rclone
- Change rclone/fs interfaces to accept context.Context - Update interface implementations to use context.Context - Change top level usage to propagate context to lover level functions Context propagation is needed for stopping transfers and passing other request-scoped values.
This commit is contained in:
committed by
Nick Craig-Wood
parent
a2c317b46e
commit
f78cd1e043
+11
-10
@@ -1,6 +1,7 @@
|
||||
package vfs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
@@ -36,7 +37,7 @@ func newDir(vfs *VFS, f fs.Fs, parent *Dir, fsDir fs.Directory) *Dir {
|
||||
parent: parent,
|
||||
entry: fsDir,
|
||||
path: fsDir.Remote(),
|
||||
modTime: fsDir.ModTime(),
|
||||
modTime: fsDir.ModTime(context.TODO()),
|
||||
inode: newInode(),
|
||||
items: make(map[string]Node),
|
||||
}
|
||||
@@ -177,7 +178,7 @@ func (d *Dir) rename(newParent *Dir, fsDir fs.Directory) {
|
||||
d.parent = newParent
|
||||
d.entry = fsDir
|
||||
d.path = fsDir.Remote()
|
||||
d.modTime = fsDir.ModTime()
|
||||
d.modTime = fsDir.ModTime(context.TODO())
|
||||
d.read = time.Time{}
|
||||
}
|
||||
|
||||
@@ -207,7 +208,7 @@ func (d *Dir) _readDir() error {
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
entries, err := list.DirSorted(d.f, false, d.path)
|
||||
entries, err := list.DirSorted(context.TODO(), d.f, false, d.path)
|
||||
if err == fs.ErrorDirNotFound {
|
||||
// We treat directory not found as empty because we
|
||||
// create directories on the fly
|
||||
@@ -294,7 +295,7 @@ func (d *Dir) readDirTree() error {
|
||||
d.mu.Unlock()
|
||||
when := time.Now()
|
||||
fs.Debugf(path, "Reading directory tree")
|
||||
dt, err := walk.NewDirTree(f, path, false, -1)
|
||||
dt, err := walk.NewDirTree(context.TODO(), f, path, false, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -477,7 +478,7 @@ func (d *Dir) Mkdir(name string) (*Dir, error) {
|
||||
return nil, err
|
||||
}
|
||||
// fs.Debugf(path, "Dir.Mkdir")
|
||||
err = d.f.Mkdir(path)
|
||||
err = d.f.Mkdir(context.TODO(), path)
|
||||
if err != nil {
|
||||
fs.Errorf(d, "Dir.Mkdir failed to create directory: %v", err)
|
||||
return nil, err
|
||||
@@ -505,7 +506,7 @@ func (d *Dir) Remove() error {
|
||||
return ENOTEMPTY
|
||||
}
|
||||
// remove directory
|
||||
err = d.f.Rmdir(d.path)
|
||||
err = d.f.Rmdir(context.TODO(), d.path)
|
||||
if err != nil {
|
||||
fs.Errorf(d, "Dir.Remove failed to remove directory: %v", err)
|
||||
return err
|
||||
@@ -575,7 +576,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
switch x := oldNode.DirEntry().(type) {
|
||||
case nil:
|
||||
if oldFile, ok := oldNode.(*File); ok {
|
||||
if err = oldFile.rename(destDir, newName); err != nil {
|
||||
if err = oldFile.rename(context.TODO(), destDir, newName); err != nil {
|
||||
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
||||
return err
|
||||
}
|
||||
@@ -585,7 +586,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
}
|
||||
case fs.Object:
|
||||
if oldFile, ok := oldNode.(*File); ok {
|
||||
if err = oldFile.rename(destDir, newName); err != nil {
|
||||
if err = oldFile.rename(context.TODO(), destDir, newName); err != nil {
|
||||
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
||||
return err
|
||||
}
|
||||
@@ -603,12 +604,12 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
}
|
||||
srcRemote := x.Remote()
|
||||
dstRemote := newPath
|
||||
err = operations.DirMove(d.f, srcRemote, dstRemote)
|
||||
err = operations.DirMove(context.TODO(), d.f, srcRemote, dstRemote)
|
||||
if err != nil {
|
||||
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
||||
return err
|
||||
}
|
||||
newDir := fs.NewDirCopy(x).SetRemote(newPath)
|
||||
newDir := fs.NewDirCopy(context.TODO(), x).SetRemote(newPath)
|
||||
// Update the node with the new details
|
||||
if oldNode != nil {
|
||||
if oldDir, ok := oldNode.(*Dir); ok {
|
||||
|
||||
Reference in New Issue
Block a user