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
+10
-8
@@ -1,6 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ncw/rclone/fs"
|
||||
"github.com/ncw/rclone/fs/rc"
|
||||
)
|
||||
@@ -23,7 +25,7 @@ See the [config dump command](/commands/rclone_config_dump/) command for more in
|
||||
}
|
||||
|
||||
// Return the config file dump
|
||||
func rcDump(in rc.Params) (out rc.Params, err error) {
|
||||
func rcDump(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
return DumpRcBlob(), nil
|
||||
}
|
||||
|
||||
@@ -43,7 +45,7 @@ See the [config dump command](/commands/rclone_config_dump/) command for more in
|
||||
}
|
||||
|
||||
// Return the config file get
|
||||
func rcGet(in rc.Params) (out rc.Params, err error) {
|
||||
func rcGet(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
name, err := in.GetString("name")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -67,7 +69,7 @@ See the [listremotes command](/commands/rclone_listremotes/) command for more in
|
||||
}
|
||||
|
||||
// Return the a list of remotes in the config file
|
||||
func rcListRemotes(in rc.Params) (out rc.Params, err error) {
|
||||
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
var remotes = []string{}
|
||||
for _, remote := range getConfigData().GetSectionList() {
|
||||
remotes = append(remotes, remote)
|
||||
@@ -94,7 +96,7 @@ See the [config providers command](/commands/rclone_config_providers/) command f
|
||||
}
|
||||
|
||||
// Return the config file providers
|
||||
func rcProviders(in rc.Params) (out rc.Params, err error) {
|
||||
func rcProviders(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
out = rc.Params{
|
||||
"providers": fs.Registry,
|
||||
}
|
||||
@@ -111,8 +113,8 @@ func init() {
|
||||
rc.Add(rc.Call{
|
||||
Path: "config/" + name,
|
||||
AuthRequired: true,
|
||||
Fn: func(in rc.Params) (rc.Params, error) {
|
||||
return rcConfig(in, name)
|
||||
Fn: func(ctx context.Context, in rc.Params) (rc.Params, error) {
|
||||
return rcConfig(ctx, in, name)
|
||||
},
|
||||
Title: name + " the config for a remote.",
|
||||
Help: `This takes the following parameters
|
||||
@@ -126,7 +128,7 @@ See the [config ` + name + ` command](/commands/rclone_config_` + name + `/) com
|
||||
}
|
||||
|
||||
// Manipulate the config file
|
||||
func rcConfig(in rc.Params, what string) (out rc.Params, err error) {
|
||||
func rcConfig(ctx context.Context, in rc.Params, what string) (out rc.Params, err error) {
|
||||
name, err := in.GetString("name")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -167,7 +169,7 @@ See the [config delete command](/commands/rclone_config_delete/) command for mor
|
||||
}
|
||||
|
||||
// Return the config file delete
|
||||
func rcDelete(in rc.Params) (out rc.Params, err error) {
|
||||
func rcDelete(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
name, err := in.GetString("name")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
_ "github.com/ncw/rclone/backend/local"
|
||||
@@ -24,7 +25,7 @@ func TestRc(t *testing.T) {
|
||||
"test_key": "sausage",
|
||||
},
|
||||
}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, out)
|
||||
assert.Equal(t, "local", FileGet(testName, "type"))
|
||||
@@ -37,7 +38,7 @@ func TestRc(t *testing.T) {
|
||||
call := rc.Calls.Get("config/dump")
|
||||
assert.NotNil(t, call)
|
||||
in := rc.Params{}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
|
||||
@@ -54,7 +55,7 @@ func TestRc(t *testing.T) {
|
||||
in := rc.Params{
|
||||
"name": testName,
|
||||
}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
|
||||
@@ -66,7 +67,7 @@ func TestRc(t *testing.T) {
|
||||
call := rc.Calls.Get("config/listremotes")
|
||||
assert.NotNil(t, call)
|
||||
in := rc.Params{}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
|
||||
@@ -87,7 +88,7 @@ func TestRc(t *testing.T) {
|
||||
"test_key2": "cabbage",
|
||||
},
|
||||
}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, out)
|
||||
|
||||
@@ -106,7 +107,7 @@ func TestRc(t *testing.T) {
|
||||
"test_key2": "cabbage",
|
||||
},
|
||||
}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, out)
|
||||
|
||||
@@ -121,7 +122,7 @@ func TestRc(t *testing.T) {
|
||||
in = rc.Params{
|
||||
"name": testName,
|
||||
}
|
||||
out, err = call.Fn(in)
|
||||
out, err = call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, out)
|
||||
assert.Equal(t, "", FileGet(testName, "type"))
|
||||
@@ -132,7 +133,7 @@ func TestRcProviders(t *testing.T) {
|
||||
call := rc.Calls.Get("config/providers")
|
||||
assert.NotNil(t, call)
|
||||
in := rc.Params{}
|
||||
out, err := call.Fn(in)
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
var registry []*fs.RegInfo
|
||||
|
||||
Reference in New Issue
Block a user