mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01: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
@@ -21,6 +21,7 @@ package operations_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -62,23 +63,23 @@ func TestMkdir(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
err := operations.Mkdir(r.Fremote, "")
|
||||
err := operations.Mkdir(context.Background(), r.Fremote, "")
|
||||
require.NoError(t, err)
|
||||
fstest.CheckListing(t, r.Fremote, []fstest.Item{})
|
||||
|
||||
err = operations.Mkdir(r.Fremote, "")
|
||||
err = operations.Mkdir(context.Background(), r.Fremote, "")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLsd(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteObject("sub dir/hello world", "hello world", t1)
|
||||
file1 := r.WriteObject(context.Background(), "sub dir/hello world", "hello world", t1)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1)
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := operations.ListDir(r.Fremote, &buf)
|
||||
err := operations.ListDir(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
res := buf.String()
|
||||
assert.Contains(t, res, "sub dir\n")
|
||||
@@ -87,13 +88,13 @@ func TestLsd(t *testing.T) {
|
||||
func TestLs(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth("empty space", "", t2)
|
||||
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth(context.Background(), "empty space", "", t2)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2)
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := operations.List(r.Fremote, &buf)
|
||||
err := operations.List(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
res := buf.String()
|
||||
assert.Contains(t, res, " 0 empty space\n")
|
||||
@@ -103,8 +104,8 @@ func TestLs(t *testing.T) {
|
||||
func TestLsWithFilesFrom(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth("empty space", "", t2)
|
||||
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth(context.Background(), "empty space", "", t2)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2)
|
||||
|
||||
@@ -122,7 +123,7 @@ func TestLsWithFilesFrom(t *testing.T) {
|
||||
}()
|
||||
|
||||
var buf bytes.Buffer
|
||||
err = operations.List(r.Fremote, &buf)
|
||||
err = operations.List(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, " 60 potato2\n", buf.String())
|
||||
|
||||
@@ -134,7 +135,7 @@ func TestLsWithFilesFrom(t *testing.T) {
|
||||
}()
|
||||
|
||||
buf.Reset()
|
||||
err = operations.List(r.Fremote, &buf)
|
||||
err = operations.List(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, " 60 potato2\n", buf.String())
|
||||
}
|
||||
@@ -142,13 +143,13 @@ func TestLsWithFilesFrom(t *testing.T) {
|
||||
func TestLsLong(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth("empty space", "", t2)
|
||||
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth(context.Background(), "empty space", "", t2)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2)
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := operations.ListLong(r.Fremote, &buf)
|
||||
err := operations.ListLong(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
res := buf.String()
|
||||
lines := strings.Split(strings.Trim(res, "\n"), "\n")
|
||||
@@ -187,15 +188,15 @@ func TestLsLong(t *testing.T) {
|
||||
func TestHashSums(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth("empty space", "", t2)
|
||||
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth(context.Background(), "empty space", "", t2)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2)
|
||||
|
||||
// MD5 Sum
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := operations.Md5sum(r.Fremote, &buf)
|
||||
err := operations.Md5sum(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
res := buf.String()
|
||||
if !strings.Contains(res, "d41d8cd98f00b204e9800998ecf8427e empty space\n") &&
|
||||
@@ -212,7 +213,7 @@ func TestHashSums(t *testing.T) {
|
||||
// SHA1 Sum
|
||||
|
||||
buf.Reset()
|
||||
err = operations.Sha1sum(r.Fremote, &buf)
|
||||
err = operations.Sha1sum(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
res = buf.String()
|
||||
if !strings.Contains(res, "da39a3ee5e6b4b0d3255bfef95601890afd80709 empty space\n") &&
|
||||
@@ -229,7 +230,7 @@ func TestHashSums(t *testing.T) {
|
||||
// Dropbox Hash Sum
|
||||
|
||||
buf.Reset()
|
||||
err = operations.DropboxHashSum(r.Fremote, &buf)
|
||||
err = operations.DropboxHashSum(context.Background(), r.Fremote, &buf)
|
||||
require.NoError(t, err)
|
||||
res = buf.String()
|
||||
if !strings.Contains(res, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 empty space\n") &&
|
||||
@@ -274,9 +275,9 @@ func TestSuffixName(t *testing.T) {
|
||||
func TestCount(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth("empty space", "", t2)
|
||||
file3 := r.WriteBoth("sub dir/potato3", "hello", t2)
|
||||
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
||||
file2 := r.WriteBoth(context.Background(), "empty space", "", t2)
|
||||
file3 := r.WriteBoth(context.Background(), "sub dir/potato3", "hello", t2)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
||||
|
||||
@@ -284,7 +285,7 @@ func TestCount(t *testing.T) {
|
||||
fs.Config.MaxDepth = 1
|
||||
defer func() { fs.Config.MaxDepth = -1 }()
|
||||
|
||||
objects, size, err := operations.Count(r.Fremote)
|
||||
objects, size, err := operations.Count(context.Background(), r.Fremote)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(2), objects)
|
||||
assert.Equal(t, int64(60), size)
|
||||
@@ -293,9 +294,9 @@ func TestCount(t *testing.T) {
|
||||
func TestDelete(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteObject("small", "1234567890", t2) // 10 bytes
|
||||
file2 := r.WriteObject("medium", "------------------------------------------------------------", t1) // 60 bytes
|
||||
file3 := r.WriteObject("large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes
|
||||
file1 := r.WriteObject(context.Background(), "small", "1234567890", t2) // 10 bytes
|
||||
file2 := r.WriteObject(context.Background(), "medium", "------------------------------------------------------------", t1) // 60 bytes
|
||||
file3 := r.WriteObject(context.Background(), "large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
||||
|
||||
filter.Active.Opt.MaxSize = 60
|
||||
@@ -303,12 +304,12 @@ func TestDelete(t *testing.T) {
|
||||
filter.Active.Opt.MaxSize = -1
|
||||
}()
|
||||
|
||||
err := operations.Delete(r.Fremote)
|
||||
err := operations.Delete(context.Background(), r.Fremote)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Fremote, file3)
|
||||
}
|
||||
|
||||
func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) error) {
|
||||
func testCheck(t *testing.T, checkFunction func(ctx context.Context, fdst, fsrc fs.Fs, oneway bool) error) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
@@ -320,7 +321,7 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
||||
defer func() {
|
||||
log.SetOutput(os.Stderr)
|
||||
}()
|
||||
err := checkFunction(r.Fremote, r.Flocal, oneway)
|
||||
err := checkFunction(context.Background(), r.Fremote, r.Flocal, oneway)
|
||||
gotErrors := accounting.Stats.GetErrors()
|
||||
gotChecks := accounting.Stats.GetChecks()
|
||||
if wantErrors == 0 && err != nil {
|
||||
@@ -341,7 +342,7 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
||||
fs.Debugf(r.Fremote, "%d: Ending check test", i)
|
||||
}
|
||||
|
||||
file1 := r.WriteBoth("rutabaga", "is tasty", t3)
|
||||
file1 := r.WriteBoth(context.Background(), "rutabaga", "is tasty", t3)
|
||||
fstest.CheckItems(t, r.Fremote, file1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
check(1, 0, 1, false)
|
||||
@@ -350,15 +351,15 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
||||
fstest.CheckItems(t, r.Flocal, file1, file2)
|
||||
check(2, 1, 1, false)
|
||||
|
||||
file3 := r.WriteObject("empty space", "", t2)
|
||||
file3 := r.WriteObject(context.Background(), "empty space", "", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file1, file3)
|
||||
check(3, 2, 1, false)
|
||||
|
||||
file2r := file2
|
||||
if fs.Config.SizeOnly {
|
||||
file2r = r.WriteObject("potato2", "--Some-Differences-But-Size-Only-Is-Enabled-----------------", t1)
|
||||
file2r = r.WriteObject(context.Background(), "potato2", "--Some-Differences-But-Size-Only-Is-Enabled-----------------", t1)
|
||||
} else {
|
||||
r.WriteObject("potato2", "------------------------------------------------------------", t1)
|
||||
r.WriteObject(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
||||
}
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2r, file3)
|
||||
check(4, 1, 2, false)
|
||||
@@ -367,7 +368,7 @@ func testCheck(t *testing.T, checkFunction func(fdst, fsrc fs.Fs, oneway bool) e
|
||||
fstest.CheckItems(t, r.Flocal, file1, file2, file3)
|
||||
check(5, 0, 3, false)
|
||||
|
||||
file4 := r.WriteObject("remotepotato", "------------------------------------------------------------", t1)
|
||||
file4 := r.WriteObject(context.Background(), "remotepotato", "------------------------------------------------------------", t1)
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2r, file3, file4)
|
||||
check(6, 1, 3, false)
|
||||
check(7, 0, 3, true)
|
||||
@@ -390,8 +391,8 @@ func TestCheckSizeOnly(t *testing.T) {
|
||||
func TestCat(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
file1 := r.WriteBoth("file1", "ABCDEFGHIJ", t1)
|
||||
file2 := r.WriteBoth("file2", "012345678", t2)
|
||||
file1 := r.WriteBoth(context.Background(), "file1", "ABCDEFGHIJ", t1)
|
||||
file2 := r.WriteBoth(context.Background(), "file2", "012345678", t2)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1, file2)
|
||||
|
||||
@@ -407,7 +408,7 @@ func TestCat(t *testing.T) {
|
||||
{1, 3, "BCD", "123"},
|
||||
} {
|
||||
var buf bytes.Buffer
|
||||
err := operations.Cat(r.Fremote, &buf, test.offset, test.count)
|
||||
err := operations.Cat(context.Background(), r.Fremote, &buf, test.offset, test.count)
|
||||
require.NoError(t, err)
|
||||
res := buf.String()
|
||||
|
||||
@@ -440,11 +441,11 @@ func TestRcat(t *testing.T) {
|
||||
path2 := prefix + "big_file_from_pipe"
|
||||
|
||||
in := ioutil.NopCloser(strings.NewReader(data1))
|
||||
_, err := operations.Rcat(r.Fremote, path1, in, t1)
|
||||
_, err := operations.Rcat(context.Background(), r.Fremote, path1, in, t1)
|
||||
require.NoError(t, err)
|
||||
|
||||
in = ioutil.NopCloser(strings.NewReader(data2))
|
||||
_, err = operations.Rcat(r.Fremote, path2, in, t2)
|
||||
_, err = operations.Rcat(context.Background(), r.Fremote, path2, in, t2)
|
||||
require.NoError(t, err)
|
||||
|
||||
file1 := fstest.NewItem(path1, data1, t1)
|
||||
@@ -459,21 +460,21 @@ func TestRcat(t *testing.T) {
|
||||
func TestPurge(t *testing.T) {
|
||||
r := fstest.NewRunIndividual(t) // make new container (azureblob has delayed mkdir after rmdir)
|
||||
defer r.Finalise()
|
||||
r.Mkdir(r.Fremote)
|
||||
r.Mkdir(context.Background(), r.Fremote)
|
||||
|
||||
// Make some files and dirs
|
||||
r.ForceMkdir(r.Fremote)
|
||||
file1 := r.WriteObject("A1/B1/C1/one", "aaa", t1)
|
||||
r.ForceMkdir(context.Background(), r.Fremote)
|
||||
file1 := r.WriteObject(context.Background(), "A1/B1/C1/one", "aaa", t1)
|
||||
//..and dirs we expect to delete
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B2/C2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B1/C3"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A3"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A3/B3"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A3/B3/C4"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B2/C2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B1/C3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A3/B3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A3/B3/C4"))
|
||||
//..and one more file at the end
|
||||
file2 := r.WriteObject("A1/two", "bbb", t2)
|
||||
file2 := r.WriteObject(context.Background(), "A1/two", "bbb", t2)
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -496,7 +497,7 @@ func TestPurge(t *testing.T) {
|
||||
fs.GetModifyWindow(r.Fremote),
|
||||
)
|
||||
|
||||
require.NoError(t, operations.Purge(r.Fremote, "A1/B1"))
|
||||
require.NoError(t, operations.Purge(context.Background(), r.Fremote, "A1/B1"))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -516,7 +517,7 @@ func TestPurge(t *testing.T) {
|
||||
fs.GetModifyWindow(r.Fremote),
|
||||
)
|
||||
|
||||
require.NoError(t, operations.Purge(r.Fremote, ""))
|
||||
require.NoError(t, operations.Purge(context.Background(), r.Fremote, ""))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -531,21 +532,21 @@ func TestPurge(t *testing.T) {
|
||||
func TestRmdirsNoLeaveRoot(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
r.Mkdir(r.Fremote)
|
||||
r.Mkdir(context.Background(), r.Fremote)
|
||||
|
||||
// Make some files and dirs we expect to keep
|
||||
r.ForceMkdir(r.Fremote)
|
||||
file1 := r.WriteObject("A1/B1/C1/one", "aaa", t1)
|
||||
r.ForceMkdir(context.Background(), r.Fremote)
|
||||
file1 := r.WriteObject(context.Background(), "A1/B1/C1/one", "aaa", t1)
|
||||
//..and dirs we expect to delete
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B2/C2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B1/C3"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A3"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A3/B3"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A3/B3/C4"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B2/C2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B1/C3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A3/B3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A3/B3/C4"))
|
||||
//..and one more file at the end
|
||||
file2 := r.WriteObject("A1/two", "bbb", t2)
|
||||
file2 := r.WriteObject(context.Background(), "A1/two", "bbb", t2)
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -568,7 +569,7 @@ func TestRmdirsNoLeaveRoot(t *testing.T) {
|
||||
fs.GetModifyWindow(r.Fremote),
|
||||
)
|
||||
|
||||
require.NoError(t, operations.Rmdirs(r.Fremote, "A3/B3/C4", false))
|
||||
require.NoError(t, operations.Rmdirs(context.Background(), r.Fremote, "A3/B3/C4", false))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -590,7 +591,7 @@ func TestRmdirsNoLeaveRoot(t *testing.T) {
|
||||
fs.GetModifyWindow(r.Fremote),
|
||||
)
|
||||
|
||||
require.NoError(t, operations.Rmdirs(r.Fremote, "", false))
|
||||
require.NoError(t, operations.Rmdirs(context.Background(), r.Fremote, "", false))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -611,13 +612,13 @@ func TestRmdirsNoLeaveRoot(t *testing.T) {
|
||||
func TestRmdirsLeaveRoot(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
r.Mkdir(r.Fremote)
|
||||
r.Mkdir(context.Background(), r.Fremote)
|
||||
|
||||
r.ForceMkdir(r.Fremote)
|
||||
r.ForceMkdir(context.Background(), r.Fremote)
|
||||
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B1"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B1/C1"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B1"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B1/C1"))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -631,7 +632,7 @@ func TestRmdirsLeaveRoot(t *testing.T) {
|
||||
fs.GetModifyWindow(r.Fremote),
|
||||
)
|
||||
|
||||
require.NoError(t, operations.Rmdirs(r.Fremote, "A1", true))
|
||||
require.NoError(t, operations.Rmdirs(context.Background(), r.Fremote, "A1", true))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -653,7 +654,7 @@ func TestRcatSize(t *testing.T) {
|
||||
file2 := r.WriteFile("potato2", body, t2)
|
||||
// Test with known length
|
||||
bodyReader := ioutil.NopCloser(strings.NewReader(body))
|
||||
obj, err := operations.RcatSize(r.Fremote, file1.Path, bodyReader, int64(len(body)), file1.ModTime)
|
||||
obj, err := operations.RcatSize(context.Background(), r.Fremote, file1.Path, bodyReader, int64(len(body)), file1.ModTime)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(len(body)), obj.Size())
|
||||
assert.Equal(t, file1.Path, obj.Remote())
|
||||
@@ -661,7 +662,7 @@ func TestRcatSize(t *testing.T) {
|
||||
// Test with unknown length
|
||||
bodyReader = ioutil.NopCloser(strings.NewReader(body)) // reset Reader
|
||||
ioutil.NopCloser(strings.NewReader(body))
|
||||
obj, err = operations.RcatSize(r.Fremote, file2.Path, bodyReader, -1, file2.ModTime)
|
||||
obj, err = operations.RcatSize(context.Background(), r.Fremote, file2.Path, bodyReader, -1, file2.ModTime)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(len(body)), obj.Size())
|
||||
assert.Equal(t, file2.Path, obj.Remote())
|
||||
@@ -677,7 +678,7 @@ func TestCopyURL(t *testing.T) {
|
||||
contents := "file contents\n"
|
||||
file1 := r.WriteFile("file1", contents, t1)
|
||||
file2 := r.WriteFile("file2", contents, t1)
|
||||
r.Mkdir(r.Fremote)
|
||||
r.Mkdir(context.Background(), r.Fremote)
|
||||
fstest.CheckItems(t, r.Fremote)
|
||||
|
||||
// check when reading from regular HTTP server
|
||||
@@ -688,7 +689,7 @@ func TestCopyURL(t *testing.T) {
|
||||
ts := httptest.NewServer(handler)
|
||||
defer ts.Close()
|
||||
|
||||
o, err := operations.CopyURL(r.Fremote, "file1", ts.URL)
|
||||
o, err := operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(len(contents)), o.Size())
|
||||
|
||||
@@ -704,7 +705,7 @@ func TestCopyURL(t *testing.T) {
|
||||
tss := httptest.NewTLSServer(handler)
|
||||
defer tss.Close()
|
||||
|
||||
o, err = operations.CopyURL(r.Fremote, "file2", tss.URL)
|
||||
o, err = operations.CopyURL(context.Background(), r.Fremote, "file2", tss.URL)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(len(contents)), o.Size())
|
||||
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2}, nil, fs.ModTimeNotSupported)
|
||||
@@ -720,7 +721,7 @@ func TestMoveFile(t *testing.T) {
|
||||
file2 := file1
|
||||
file2.Path = "sub/file2"
|
||||
|
||||
err := operations.MoveFile(r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
err := operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
@@ -728,12 +729,12 @@ func TestMoveFile(t *testing.T) {
|
||||
r.WriteFile("file1", "file1 contents", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
err = operations.MoveFile(r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
err = operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
|
||||
err = operations.MoveFile(r.Fremote, r.Fremote, file2.Path, file2.Path)
|
||||
err = operations.MoveFile(context.Background(), r.Fremote, r.Fremote, file2.Path, file2.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
@@ -752,7 +753,7 @@ func TestCaseInsensitiveMoveFile(t *testing.T) {
|
||||
file2 := file1
|
||||
file2.Path = "sub/file2"
|
||||
|
||||
err := operations.MoveFile(r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
err := operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
@@ -760,7 +761,7 @@ func TestCaseInsensitiveMoveFile(t *testing.T) {
|
||||
r.WriteFile("file1", "file1 contents", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
err = operations.MoveFile(r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
err = operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
@@ -768,7 +769,7 @@ func TestCaseInsensitiveMoveFile(t *testing.T) {
|
||||
file2Capitalized := file2
|
||||
file2Capitalized.Path = "sub/File2"
|
||||
|
||||
err = operations.MoveFile(r.Fremote, r.Fremote, file2Capitalized.Path, file2.Path)
|
||||
err = operations.MoveFile(context.Background(), r.Fremote, r.Fremote, file2Capitalized.Path, file2.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
fstest.CheckItems(t, r.Fremote, file2Capitalized)
|
||||
@@ -787,10 +788,10 @@ func TestMoveFileBackupDir(t *testing.T) {
|
||||
file1 := r.WriteFile("dst/file1", "file1 contents", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
file1old := r.WriteObject("dst/file1", "file1 contents old", t1)
|
||||
file1old := r.WriteObject(context.Background(), "dst/file1", "file1 contents old", t1)
|
||||
fstest.CheckItems(t, r.Fremote, file1old)
|
||||
|
||||
err := operations.MoveFile(r.Fremote, r.Flocal, file1.Path, file1.Path)
|
||||
err := operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file1.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal)
|
||||
file1old.Path = "backup/dst/file1"
|
||||
@@ -807,17 +808,17 @@ func TestCopyFile(t *testing.T) {
|
||||
file2 := file1
|
||||
file2.Path = "sub/file2"
|
||||
|
||||
err := operations.CopyFile(r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
err := operations.CopyFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
|
||||
err = operations.CopyFile(r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
err = operations.CopyFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
|
||||
err = operations.CopyFile(r.Fremote, r.Fremote, file2.Path, file2.Path)
|
||||
err = operations.CopyFile(context.Background(), r.Fremote, r.Fremote, file2.Path, file2.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
fstest.CheckItems(t, r.Fremote, file2)
|
||||
@@ -836,10 +837,10 @@ func TestCopyFileBackupDir(t *testing.T) {
|
||||
file1 := r.WriteFile("dst/file1", "file1 contents", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
file1old := r.WriteObject("dst/file1", "file1 contents old", t1)
|
||||
file1old := r.WriteObject(context.Background(), "dst/file1", "file1 contents old", t1)
|
||||
fstest.CheckItems(t, r.Fremote, file1old)
|
||||
|
||||
err := operations.CopyFile(r.Fremote, r.Flocal, file1.Path, file1.Path)
|
||||
err := operations.CopyFile(context.Background(), r.Fremote, r.Flocal, file1.Path, file1.Path)
|
||||
require.NoError(t, err)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
file1old.Path = "backup/dst/file1"
|
||||
@@ -1135,19 +1136,19 @@ func TestDirMove(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
r.Mkdir(r.Fremote)
|
||||
r.Mkdir(context.Background(), r.Fremote)
|
||||
|
||||
// Make some files and dirs
|
||||
r.ForceMkdir(r.Fremote)
|
||||
r.ForceMkdir(context.Background(), r.Fremote)
|
||||
files := []fstest.Item{
|
||||
r.WriteObject("A1/one", "one", t1),
|
||||
r.WriteObject("A1/two", "two", t2),
|
||||
r.WriteObject("A1/B1/three", "three", t3),
|
||||
r.WriteObject("A1/B1/C1/four", "four", t1),
|
||||
r.WriteObject("A1/B1/C2/five", "five", t2),
|
||||
r.WriteObject(context.Background(), "A1/one", "one", t1),
|
||||
r.WriteObject(context.Background(), "A1/two", "two", t2),
|
||||
r.WriteObject(context.Background(), "A1/B1/three", "three", t3),
|
||||
r.WriteObject(context.Background(), "A1/B1/C1/four", "four", t1),
|
||||
r.WriteObject(context.Background(), "A1/B1/C2/five", "five", t2),
|
||||
}
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B2"))
|
||||
require.NoError(t, operations.Mkdir(r.Fremote, "A1/B1/C3"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B2"))
|
||||
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B1/C3"))
|
||||
|
||||
fstest.CheckListingWithPrecision(
|
||||
t,
|
||||
@@ -1164,7 +1165,7 @@ func TestDirMove(t *testing.T) {
|
||||
fs.GetModifyWindow(r.Fremote),
|
||||
)
|
||||
|
||||
require.NoError(t, operations.DirMove(r.Fremote, "A1", "A2"))
|
||||
require.NoError(t, operations.DirMove(context.Background(), r.Fremote, "A1", "A2"))
|
||||
|
||||
for i := range files {
|
||||
files[i].Path = strings.Replace(files[i].Path, "A1/", "A2/", -1)
|
||||
@@ -1194,7 +1195,7 @@ func TestDirMove(t *testing.T) {
|
||||
features.DirMove = oldDirMove
|
||||
}()
|
||||
|
||||
require.NoError(t, operations.DirMove(r.Fremote, "A2", "A3"))
|
||||
require.NoError(t, operations.DirMove(context.Background(), r.Fremote, "A2", "A3"))
|
||||
|
||||
for i := range files {
|
||||
files[i].Path = strings.Replace(files[i].Path, "A2/", "A3/", -1)
|
||||
|
||||
Reference in New Issue
Block a user