mirror of
https://github.com/rclone/rclone.git
synced 2026-01-03 17:13:18 +00:00
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
@@ -1,6 +1,7 @@
|
||||
package operations_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/ncw/rclone/fs"
|
||||
@@ -23,13 +24,13 @@ func TestListDirSorted(t *testing.T) {
|
||||
}()
|
||||
|
||||
files := []fstest.Item{
|
||||
r.WriteObject("a.txt", "hello world", t1),
|
||||
r.WriteObject("zend.txt", "hello", t1),
|
||||
r.WriteObject("sub dir/hello world", "hello world", t1),
|
||||
r.WriteObject("sub dir/hello world2", "hello world", t1),
|
||||
r.WriteObject("sub dir/ignore dir/.ignore", "", t1),
|
||||
r.WriteObject("sub dir/ignore dir/should be ignored", "to ignore", t1),
|
||||
r.WriteObject("sub dir/sub sub dir/hello world3", "hello world", t1),
|
||||
r.WriteObject(context.Background(), "a.txt", "hello world", t1),
|
||||
r.WriteObject(context.Background(), "zend.txt", "hello", t1),
|
||||
r.WriteObject(context.Background(), "sub dir/hello world", "hello world", t1),
|
||||
r.WriteObject(context.Background(), "sub dir/hello world2", "hello world", t1),
|
||||
r.WriteObject(context.Background(), "sub dir/ignore dir/.ignore", "", t1),
|
||||
r.WriteObject(context.Background(), "sub dir/ignore dir/should be ignored", "to ignore", t1),
|
||||
r.WriteObject(context.Background(), "sub dir/sub sub dir/hello world3", "hello world", t1),
|
||||
}
|
||||
fstest.CheckItems(t, r.Fremote, files...)
|
||||
var items fs.DirEntries
|
||||
@@ -50,20 +51,20 @@ func TestListDirSorted(t *testing.T) {
|
||||
return name
|
||||
}
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, true, "")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, true, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 3)
|
||||
assert.Equal(t, "a.txt", str(0))
|
||||
assert.Equal(t, "sub dir/", str(1))
|
||||
assert.Equal(t, "zend.txt", str(2))
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, false, "")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, false, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 2)
|
||||
assert.Equal(t, "sub dir/", str(0))
|
||||
assert.Equal(t, "zend.txt", str(1))
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, true, "sub dir")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, true, "sub dir")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 4)
|
||||
assert.Equal(t, "sub dir/hello world", str(0))
|
||||
@@ -71,7 +72,7 @@ func TestListDirSorted(t *testing.T) {
|
||||
assert.Equal(t, "sub dir/ignore dir/", str(2))
|
||||
assert.Equal(t, "sub dir/sub sub dir/", str(3))
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, false, "sub dir")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, false, "sub dir")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 2)
|
||||
assert.Equal(t, "sub dir/ignore dir/", str(0))
|
||||
@@ -80,23 +81,23 @@ func TestListDirSorted(t *testing.T) {
|
||||
// testing ignore file
|
||||
filter.Active.Opt.ExcludeFile = ".ignore"
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, false, "sub dir")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, false, "sub dir")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 1)
|
||||
assert.Equal(t, "sub dir/sub sub dir/", str(0))
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, false, "sub dir/ignore dir")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, false, "sub dir/ignore dir")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 0)
|
||||
|
||||
items, err = list.DirSorted(r.Fremote, true, "sub dir/ignore dir")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, true, "sub dir/ignore dir")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 2)
|
||||
assert.Equal(t, "sub dir/ignore dir/.ignore", str(0))
|
||||
assert.Equal(t, "sub dir/ignore dir/should be ignored", str(1))
|
||||
|
||||
filter.Active.Opt.ExcludeFile = ""
|
||||
items, err = list.DirSorted(r.Fremote, false, "sub dir/ignore dir")
|
||||
items, err = list.DirSorted(context.Background(), r.Fremote, false, "sub dir/ignore dir")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 2)
|
||||
assert.Equal(t, "sub dir/ignore dir/.ignore", str(0))
|
||||
|
||||
Reference in New Issue
Block a user