2016-01-17 18:08:28 +08:00
|
|
|
// Integration tests - test rclone by doing real transactions to a
|
|
|
|
// storage provider to and from the local disk.
|
|
|
|
//
|
|
|
|
// By default it will use a local fs, however you can provide a
|
|
|
|
// -remote option to use a different remote. The test_all.go script
|
|
|
|
// is a wrapper to call this for all the test remotes.
|
|
|
|
//
|
|
|
|
// FIXME not safe for concurrent running of tests until fs.Config is
|
|
|
|
// no longer a global
|
|
|
|
//
|
|
|
|
// NB When writing tests
|
|
|
|
//
|
|
|
|
// Make sure every series of writes to the remote has a
|
|
|
|
// fstest.CheckItems() before use. This make sure the directory
|
|
|
|
// listing is now consistent and stops cascading errors.
|
|
|
|
//
|
2019-07-18 18:13:54 +08:00
|
|
|
// Call accounting.GlobalStats().ResetCounters() before every fs.Sync() as it
|
2018-01-13 00:30:54 +08:00
|
|
|
// uses the error count internally.
|
2014-08-02 00:58:39 +08:00
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
package operations_test
|
2014-08-02 00:58:39 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-06-17 16:34:30 +08:00
|
|
|
"context"
|
2017-01-11 22:59:53 +08:00
|
|
|
"fmt"
|
2017-02-13 18:48:26 +08:00
|
|
|
"io"
|
2020-02-14 20:26:52 +08:00
|
|
|
"io/ioutil"
|
2018-11-03 01:29:57 +08:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2018-12-31 19:58:55 +08:00
|
|
|
"os"
|
2014-08-02 00:58:39 +08:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
_ "github.com/rclone/rclone/backend/all" // import all backends
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/accounting"
|
|
|
|
"github.com/rclone/rclone/fs/filter"
|
2019-10-31 03:23:17 +08:00
|
|
|
"github.com/rclone/rclone/fs/fserrors"
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs/fshttp"
|
|
|
|
"github.com/rclone/rclone/fs/hash"
|
|
|
|
"github.com/rclone/rclone/fs/operations"
|
|
|
|
"github.com/rclone/rclone/fstest"
|
2020-03-16 22:05:49 +08:00
|
|
|
"github.com/rclone/rclone/lib/random"
|
2016-06-25 21:28:26 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-06-30 00:59:31 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2014-08-02 00:58:39 +08:00
|
|
|
)
|
|
|
|
|
2016-01-17 18:08:28 +08:00
|
|
|
// Some times used in the tests
|
|
|
|
var (
|
|
|
|
t1 = fstest.Time("2001-02-03T04:05:06.499999999Z")
|
|
|
|
t2 = fstest.Time("2011-12-25T12:59:59.123456789Z")
|
|
|
|
t3 = fstest.Time("2011-12-30T12:59:59.000000000Z")
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestMain drives the tests
|
|
|
|
func TestMain(m *testing.M) {
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.TestMain(m)
|
2014-08-02 00:58:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMkdir(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-01-17 18:08:28 +08:00
|
|
|
defer r.Finalise()
|
2018-01-13 00:30:54 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.Mkdir(context.Background(), r.Fremote, "")
|
2018-01-13 00:30:54 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckListing(t, r.Fremote, []fstest.Item{})
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.Mkdir(context.Background(), r.Fremote, "")
|
2018-01-13 00:30:54 +08:00
|
|
|
require.NoError(t, err)
|
2014-08-02 00:58:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLsd(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-01-17 18:08:28 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteObject(context.Background(), "sub dir/hello world", "hello world", t1)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2014-08-02 00:58:39 +08:00
|
|
|
var buf bytes.Buffer
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.ListDir(context.Background(), r.Fremote, &buf)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
2014-08-02 00:58:39 +08:00
|
|
|
res := buf.String()
|
2016-06-30 00:59:31 +08:00
|
|
|
assert.Contains(t, res, "sub dir\n")
|
2014-08-02 00:58:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLs(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-01-17 18:08:28 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 09:17:18 +08:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2014-08-02 00:58:39 +08:00
|
|
|
var buf bytes.Buffer
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.List(context.Background(), r.Fremote, &buf)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
2014-08-02 00:58:39 +08:00
|
|
|
res := buf.String()
|
2019-06-29 09:17:18 +08:00
|
|
|
assert.Contains(t, res, " 1 empty space\n")
|
2016-06-30 00:59:31 +08:00
|
|
|
assert.Contains(t, res, " 60 potato2\n")
|
2014-08-02 00:58:39 +08:00
|
|
|
}
|
|
|
|
|
2018-10-20 00:41:14 +08:00
|
|
|
func TestLsWithFilesFrom(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 09:17:18 +08:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2018-10-20 00:41:14 +08:00
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
|
|
|
|
// Set the --files-from equivalent
|
|
|
|
f, err := filter.NewFilter(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.AddFile("potato2"))
|
|
|
|
require.NoError(t, f.AddFile("notfound"))
|
|
|
|
|
|
|
|
// Monkey patch the active filter
|
|
|
|
oldFilter := filter.Active
|
|
|
|
filter.Active = f
|
|
|
|
defer func() {
|
|
|
|
filter.Active = oldFilter
|
|
|
|
}()
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.List(context.Background(), r.Fremote, &buf)
|
2018-10-20 00:41:14 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, " 60 potato2\n", buf.String())
|
2019-02-14 01:14:51 +08:00
|
|
|
|
|
|
|
// Now try with --no-traverse
|
|
|
|
oldNoTraverse := fs.Config.NoTraverse
|
|
|
|
fs.Config.NoTraverse = true
|
|
|
|
defer func() {
|
|
|
|
fs.Config.NoTraverse = oldNoTraverse
|
|
|
|
}()
|
|
|
|
|
|
|
|
buf.Reset()
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.List(context.Background(), r.Fremote, &buf)
|
2019-02-14 01:14:51 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, " 60 potato2\n", buf.String())
|
2018-10-20 00:41:14 +08:00
|
|
|
}
|
|
|
|
|
2014-08-02 00:58:39 +08:00
|
|
|
func TestLsLong(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-01-17 18:08:28 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 09:17:18 +08:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2014-08-02 00:58:39 +08:00
|
|
|
var buf bytes.Buffer
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.ListLong(context.Background(), r.Fremote, &buf)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
2014-08-02 00:58:39 +08:00
|
|
|
res := buf.String()
|
2015-08-17 06:24:34 +08:00
|
|
|
lines := strings.Split(strings.Trim(res, "\n"), "\n")
|
2016-06-30 00:59:31 +08:00
|
|
|
assert.Equal(t, 2, len(lines))
|
2015-08-17 06:24:34 +08:00
|
|
|
|
|
|
|
timeFormat := "2006-01-02 15:04:05.000000000"
|
2017-10-29 20:23:10 +08:00
|
|
|
precision := r.Fremote.Precision()
|
2015-09-23 02:04:12 +08:00
|
|
|
location := time.Now().Location()
|
2015-08-17 06:24:34 +08:00
|
|
|
checkTime := func(m, filename string, expected time.Time) {
|
2015-09-23 02:04:12 +08:00
|
|
|
modTime, err := time.ParseInLocation(timeFormat, m, location) // parse as localtime
|
2015-08-17 06:24:34 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error parsing %q: %v", m, err)
|
|
|
|
} else {
|
2020-04-21 22:46:01 +08:00
|
|
|
fstest.AssertTimeEqualWithPrecision(t, filename, expected, modTime, precision)
|
2015-08-17 06:24:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-29 09:17:18 +08:00
|
|
|
m1 := regexp.MustCompile(`(?m)^ 1 (\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{9}) empty space$`)
|
2015-08-17 06:24:34 +08:00
|
|
|
if ms := m1.FindStringSubmatch(res); ms == nil {
|
2014-08-02 00:58:39 +08:00
|
|
|
t.Errorf("empty space missing: %q", res)
|
2015-08-17 06:24:34 +08:00
|
|
|
} else {
|
|
|
|
checkTime(ms[1], "empty space", t2.Local())
|
2014-08-02 00:58:39 +08:00
|
|
|
}
|
2015-08-17 06:24:34 +08:00
|
|
|
|
|
|
|
m2 := regexp.MustCompile(`(?m)^ 60 (\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{9}) potato2$`)
|
|
|
|
if ms := m2.FindStringSubmatch(res); ms == nil {
|
2014-08-02 00:58:39 +08:00
|
|
|
t.Errorf("potato2 missing: %q", res)
|
2015-08-17 06:24:34 +08:00
|
|
|
} else {
|
|
|
|
checkTime(ms[1], "potato2", t1.Local())
|
2014-08-02 00:58:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 22:09:31 +08:00
|
|
|
func TestHashSums(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-01-17 18:08:28 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 09:17:18 +08:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-05-26 22:09:31 +08:00
|
|
|
// MD5 Sum
|
|
|
|
|
2014-08-02 00:58:39 +08:00
|
|
|
var buf bytes.Buffer
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.Md5sum(context.Background(), r.Fremote, &buf)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
2014-08-02 00:58:39 +08:00
|
|
|
res := buf.String()
|
2019-06-29 09:17:18 +08:00
|
|
|
if !strings.Contains(res, "336d5ebc5436534e61d16e63ddfca327 empty space\n") &&
|
2016-01-16 17:44:46 +08:00
|
|
|
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
2015-08-17 06:24:34 +08:00
|
|
|
!strings.Contains(res, " empty space\n") {
|
2014-08-02 00:58:39 +08:00
|
|
|
t.Errorf("empty space missing: %q", res)
|
|
|
|
}
|
2017-06-07 06:21:47 +08:00
|
|
|
if !strings.Contains(res, "d6548b156ea68a4e003e786df99eee76 potato2\n") &&
|
2016-01-16 17:44:46 +08:00
|
|
|
!strings.Contains(res, " UNSUPPORTED potato2\n") &&
|
2015-08-17 06:24:34 +08:00
|
|
|
!strings.Contains(res, " potato2\n") {
|
2014-08-02 00:58:39 +08:00
|
|
|
t.Errorf("potato2 missing: %q", res)
|
|
|
|
}
|
|
|
|
|
2017-05-26 22:09:31 +08:00
|
|
|
// SHA1 Sum
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-06-07 06:21:47 +08:00
|
|
|
buf.Reset()
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.Sha1sum(context.Background(), r.Fremote, &buf)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
2017-05-26 22:09:31 +08:00
|
|
|
res = buf.String()
|
2019-06-29 09:17:18 +08:00
|
|
|
if !strings.Contains(res, "3bc15c8aae3e4124dd409035f32ea2fd6835efc9 empty space\n") &&
|
2016-01-17 18:08:28 +08:00
|
|
|
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
|
|
|
!strings.Contains(res, " empty space\n") {
|
|
|
|
t.Errorf("empty space missing: %q", res)
|
|
|
|
}
|
|
|
|
if !strings.Contains(res, "9dc7f7d3279715991a22853f5981df582b7f9f6d potato2\n") &&
|
|
|
|
!strings.Contains(res, " UNSUPPORTED potato2\n") &&
|
|
|
|
!strings.Contains(res, " potato2\n") {
|
|
|
|
t.Errorf("potato2 missing: %q", res)
|
|
|
|
}
|
2019-10-27 03:27:33 +08:00
|
|
|
|
|
|
|
// QuickXorHash Sum
|
|
|
|
|
|
|
|
buf.Reset()
|
|
|
|
var ht hash.Type
|
|
|
|
err = ht.Set("QuickXorHash")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = operations.HashLister(context.Background(), ht, r.Fremote, &buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
res = buf.String()
|
|
|
|
if !strings.Contains(res, "2d00000000000000000000000100000000000000 empty space\n") &&
|
|
|
|
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
|
|
|
!strings.Contains(res, " empty space\n") {
|
|
|
|
t.Errorf("empty space missing: %q", res)
|
|
|
|
}
|
|
|
|
if !strings.Contains(res, "4001dad296b6b4a52d6d694b67dad296b6b4a52d potato2\n") &&
|
|
|
|
!strings.Contains(res, " UNSUPPORTED potato2\n") &&
|
|
|
|
!strings.Contains(res, " potato2\n") {
|
|
|
|
t.Errorf("potato2 missing: %q", res)
|
|
|
|
}
|
|
|
|
|
|
|
|
// QuickXorHash Sum with Base64 Encoded
|
|
|
|
|
|
|
|
buf.Reset()
|
|
|
|
err = operations.HashListerBase64(context.Background(), ht, r.Fremote, &buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
res = buf.String()
|
|
|
|
if !strings.Contains(res, "LQAAAAAAAAAAAAAAAQAAAAAAAAA= empty space\n") &&
|
|
|
|
!strings.Contains(res, " UNSUPPORTED empty space\n") &&
|
|
|
|
!strings.Contains(res, " empty space\n") {
|
|
|
|
t.Errorf("empty space missing: %q", res)
|
|
|
|
}
|
|
|
|
if !strings.Contains(res, "QAHa0pa2tKUtbWlLZ9rSlra0pS0= potato2\n") &&
|
|
|
|
!strings.Contains(res, " UNSUPPORTED potato2\n") &&
|
|
|
|
!strings.Contains(res, " potato2\n") {
|
|
|
|
t.Errorf("potato2 missing: %q", res)
|
|
|
|
}
|
2016-01-17 18:08:28 +08:00
|
|
|
}
|
|
|
|
|
2019-03-11 00:50:28 +08:00
|
|
|
func TestSuffixName(t *testing.T) {
|
|
|
|
origSuffix, origKeepExt := fs.Config.Suffix, fs.Config.SuffixKeepExtension
|
|
|
|
defer func() {
|
|
|
|
fs.Config.Suffix, fs.Config.SuffixKeepExtension = origSuffix, origKeepExt
|
|
|
|
}()
|
|
|
|
for _, test := range []struct {
|
|
|
|
remote string
|
|
|
|
suffix string
|
|
|
|
keepExt bool
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{"test.txt", "", false, "test.txt"},
|
|
|
|
{"test.txt", "", true, "test.txt"},
|
|
|
|
{"test.txt", "-suffix", false, "test.txt-suffix"},
|
|
|
|
{"test.txt", "-suffix", true, "test-suffix.txt"},
|
|
|
|
{"test.txt.csv", "-suffix", false, "test.txt.csv-suffix"},
|
|
|
|
{"test.txt.csv", "-suffix", true, "test.txt-suffix.csv"},
|
|
|
|
{"test", "-suffix", false, "test-suffix"},
|
|
|
|
{"test", "-suffix", true, "test-suffix"},
|
|
|
|
} {
|
|
|
|
fs.Config.Suffix = test.suffix
|
|
|
|
fs.Config.SuffixKeepExtension = test.keepExt
|
|
|
|
got := operations.SuffixName(test.remote)
|
|
|
|
assert.Equal(t, test.want, got, fmt.Sprintf("%+v", test))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 02:48:48 +08:00
|
|
|
func TestCount(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-01-17 18:08:28 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteBoth(context.Background(), "potato2", "------------------------------------------------------------", t1)
|
2019-06-29 09:17:18 +08:00
|
|
|
file2 := r.WriteBoth(context.Background(), "empty space", "-", t2)
|
2019-06-17 16:34:30 +08:00
|
|
|
file3 := r.WriteBoth(context.Background(), "sub dir/potato3", "hello", t2)
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
2016-06-03 04:02:44 +08:00
|
|
|
|
|
|
|
// Check the MaxDepth too
|
|
|
|
fs.Config.MaxDepth = 1
|
|
|
|
defer func() { fs.Config.MaxDepth = -1 }()
|
2016-01-17 18:08:28 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
objects, size, err := operations.Count(context.Background(), r.Fremote)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), objects)
|
2019-06-29 09:17:18 +08:00
|
|
|
assert.Equal(t, int64(61), size)
|
2015-10-03 02:48:48 +08:00
|
|
|
}
|
|
|
|
|
2015-12-03 06:25:32 +08:00
|
|
|
func TestDelete(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2015-12-03 06:25:32 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
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
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
|
2015-12-03 06:25:32 +08:00
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
filter.Active.Opt.MaxSize = 60
|
2015-12-03 06:25:32 +08:00
|
|
|
defer func() {
|
2018-01-13 00:30:54 +08:00
|
|
|
filter.Active.Opt.MaxSize = -1
|
2015-12-03 06:25:32 +08:00
|
|
|
}()
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.Delete(context.Background(), r.Fremote)
|
2016-06-30 00:59:31 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file3)
|
2015-12-03 06:25:32 +08:00
|
|
|
}
|
|
|
|
|
2020-06-13 00:01:23 +08:00
|
|
|
func TestRetry(t *testing.T) {
|
|
|
|
var i int
|
|
|
|
var err error
|
|
|
|
fn := func() error {
|
|
|
|
i--
|
|
|
|
if i <= 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
i, err = 3, io.EOF
|
|
|
|
assert.Equal(t, nil, operations.Retry(nil, 5, fn))
|
|
|
|
assert.Equal(t, 0, i)
|
|
|
|
|
|
|
|
i, err = 10, io.EOF
|
|
|
|
assert.Equal(t, io.EOF, operations.Retry(nil, 5, fn))
|
|
|
|
assert.Equal(t, 5, i)
|
|
|
|
|
|
|
|
i, err = 10, fs.ErrorObjectNotFound
|
|
|
|
assert.Equal(t, fs.ErrorObjectNotFound, operations.Retry(nil, 5, fn))
|
|
|
|
assert.Equal(t, 9, i)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-19 05:43:02 +08:00
|
|
|
func TestCat(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-08-19 05:43:02 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
file1 := r.WriteBoth(context.Background(), "file1", "ABCDEFGHIJ", t1)
|
|
|
|
file2 := r.WriteBoth(context.Background(), "file2", "012345678", t2)
|
2016-08-19 05:43:02 +08:00
|
|
|
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
2016-08-19 05:43:02 +08:00
|
|
|
|
2017-02-08 16:09:41 +08:00
|
|
|
for _, test := range []struct {
|
|
|
|
offset int64
|
|
|
|
count int64
|
|
|
|
a string
|
|
|
|
b string
|
|
|
|
}{
|
|
|
|
{0, -1, "ABCDEFGHIJ", "012345678"},
|
|
|
|
{0, 5, "ABCDE", "01234"},
|
|
|
|
{-3, -1, "HIJ", "678"},
|
2017-06-10 20:48:00 +08:00
|
|
|
{1, 3, "BCD", "123"},
|
2017-02-08 16:09:41 +08:00
|
|
|
} {
|
|
|
|
var buf bytes.Buffer
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.Cat(context.Background(), r.Fremote, &buf, test.offset, test.count)
|
2017-02-08 16:09:41 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
res := buf.String()
|
2016-08-19 05:43:02 +08:00
|
|
|
|
2017-02-08 16:09:41 +08:00
|
|
|
if res != test.a+test.b && res != test.b+test.a {
|
|
|
|
t.Errorf("Incorrect output from Cat(%d,%d): %q", test.offset, test.count, res)
|
|
|
|
}
|
2016-08-19 05:43:02 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 19:49:31 +08:00
|
|
|
|
2018-10-27 06:47:23 +08:00
|
|
|
func TestPurge(t *testing.T) {
|
2018-11-15 01:14:02 +08:00
|
|
|
r := fstest.NewRunIndividual(t) // make new container (azureblob has delayed mkdir after rmdir)
|
2018-10-27 06:47:23 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-10-27 06:47:23 +08:00
|
|
|
|
|
|
|
// Make some files and dirs
|
2019-06-17 16:34:30 +08:00
|
|
|
r.ForceMkdir(context.Background(), r.Fremote)
|
|
|
|
file1 := r.WriteObject(context.Background(), "A1/B1/C1/one", "aaa", t1)
|
2018-10-27 06:47:23 +08:00
|
|
|
//..and dirs we expect to delete
|
2019-06-17 16:34:30 +08:00
|
|
|
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"))
|
2018-10-27 06:47:23 +08:00
|
|
|
//..and one more file at the end
|
2019-06-17 16:34:30 +08:00
|
|
|
file2 := r.WriteObject(context.Background(), "A1/two", "bbb", t2)
|
2018-10-27 06:47:23 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1, file2,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A1/B1",
|
|
|
|
"A1/B1/C1",
|
|
|
|
"A2",
|
|
|
|
"A1/B2",
|
|
|
|
"A1/B2/C2",
|
|
|
|
"A1/B1/C3",
|
|
|
|
"A3",
|
|
|
|
"A3/B3",
|
|
|
|
"A3/B3/C4",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.Purge(context.Background(), r.Fremote, "A1/B1"))
|
2018-10-27 06:47:23 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file2,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A2",
|
|
|
|
"A1/B2",
|
|
|
|
"A1/B2/C2",
|
|
|
|
"A3",
|
|
|
|
"A3/B3",
|
|
|
|
"A3/B3/C4",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.Purge(context.Background(), r.Fremote, ""))
|
2018-10-27 06:47:23 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{},
|
|
|
|
[]string{},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:23:54 +08:00
|
|
|
func TestRmdirsNoLeaveRoot(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-11-27 19:49:31 +08:00
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2016-11-28 20:23:24 +08:00
|
|
|
|
2016-11-27 19:49:31 +08:00
|
|
|
// Make some files and dirs we expect to keep
|
2019-06-17 16:34:30 +08:00
|
|
|
r.ForceMkdir(context.Background(), r.Fremote)
|
|
|
|
file1 := r.WriteObject(context.Background(), "A1/B1/C1/one", "aaa", t1)
|
2016-11-27 19:49:31 +08:00
|
|
|
//..and dirs we expect to delete
|
2019-06-17 16:34:30 +08:00
|
|
|
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"))
|
2017-04-27 01:41:01 +08:00
|
|
|
//..and one more file at the end
|
2019-06-17 16:34:30 +08:00
|
|
|
file2 := r.WriteObject(context.Background(), "A1/two", "bbb", t2)
|
2016-11-27 19:49:31 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 20:23:10 +08:00
|
|
|
r.Fremote,
|
2016-11-27 19:49:31 +08:00
|
|
|
[]fstest.Item{
|
|
|
|
file1, file2,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A1/B1",
|
|
|
|
"A1/B1/C1",
|
|
|
|
"A2",
|
|
|
|
"A1/B2",
|
|
|
|
"A1/B2/C2",
|
|
|
|
"A1/B1/C3",
|
|
|
|
"A3",
|
|
|
|
"A3/B3",
|
|
|
|
"A3/B3/C4",
|
2017-08-09 22:51:27 +08:00
|
|
|
},
|
2018-06-04 02:45:34 +08:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2016-11-27 19:49:31 +08:00
|
|
|
)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.Rmdirs(context.Background(), r.Fremote, "A3/B3/C4", false))
|
2018-10-27 06:47:23 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{
|
|
|
|
file1, file2,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A1/B1",
|
|
|
|
"A1/B1/C1",
|
|
|
|
"A2",
|
|
|
|
"A1/B2",
|
|
|
|
"A1/B2/C2",
|
|
|
|
"A1/B1/C3",
|
|
|
|
"A3",
|
|
|
|
"A3/B3",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.Rmdirs(context.Background(), r.Fremote, "", false))
|
2016-11-27 19:49:31 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
2017-10-29 20:23:10 +08:00
|
|
|
r.Fremote,
|
2016-11-27 19:49:31 +08:00
|
|
|
[]fstest.Item{
|
|
|
|
file1, file2,
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A1/B1",
|
|
|
|
"A1/B1/C1",
|
|
|
|
},
|
2018-06-04 02:45:34 +08:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2016-11-27 19:49:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
}
|
2016-10-24 00:34:17 +08:00
|
|
|
|
2017-12-13 18:23:54 +08:00
|
|
|
func TestRmdirsLeaveRoot(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2019-06-17 16:34:30 +08:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2017-12-13 18:23:54 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
r.ForceMkdir(context.Background(), r.Fremote)
|
2017-12-13 18:23:54 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
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"))
|
2017-12-13 18:23:54 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A1/B1",
|
|
|
|
"A1/B1/C1",
|
|
|
|
},
|
2018-06-04 02:45:34 +08:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-12-13 18:23:54 +08:00
|
|
|
)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.Rmdirs(context.Background(), r.Fremote, "A1", true))
|
2017-12-13 18:23:54 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
[]fstest.Item{},
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
},
|
2018-06-04 02:45:34 +08:00
|
|
|
fs.GetModifyWindow(r.Fremote),
|
2017-12-13 18:23:54 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-11-03 01:29:57 +08:00
|
|
|
func TestCopyURL(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
2019-03-09 04:33:22 +08:00
|
|
|
contents := "file contents\n"
|
2018-11-03 01:29:57 +08:00
|
|
|
file1 := r.WriteFile("file1", contents, t1)
|
2019-03-09 04:33:22 +08:00
|
|
|
file2 := r.WriteFile("file2", contents, t1)
|
2019-06-17 16:34:30 +08:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-11-03 01:29:57 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote)
|
|
|
|
|
2019-03-09 04:33:22 +08:00
|
|
|
// check when reading from regular HTTP server
|
2019-08-06 02:20:50 +08:00
|
|
|
status := 0
|
2019-03-09 04:33:22 +08:00
|
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2019-08-06 02:20:50 +08:00
|
|
|
if status != 0 {
|
|
|
|
http.Error(w, "an error ocurred", status)
|
|
|
|
}
|
2018-11-03 01:29:57 +08:00
|
|
|
_, err := w.Write([]byte(contents))
|
|
|
|
assert.NoError(t, err)
|
2019-03-09 04:33:22 +08:00
|
|
|
})
|
|
|
|
ts := httptest.NewServer(handler)
|
2018-11-03 01:29:57 +08:00
|
|
|
defer ts.Close()
|
|
|
|
|
2020-04-19 19:40:17 +08:00
|
|
|
o, err := operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, false, false)
|
2018-11-03 01:29:57 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(len(contents)), o.Size())
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, nil, fs.ModTimeNotSupported)
|
2019-03-09 04:33:22 +08:00
|
|
|
|
2020-04-19 19:40:17 +08:00
|
|
|
// Check file clobbering
|
|
|
|
o, err = operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, false, true)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2019-09-04 00:25:19 +08:00
|
|
|
// Check auto file naming
|
|
|
|
status = 0
|
|
|
|
urlFileName := "filename.txt"
|
2020-04-19 19:40:17 +08:00
|
|
|
o, err = operations.CopyURL(context.Background(), r.Fremote, "", ts.URL+"/"+urlFileName, true, false)
|
2019-09-04 00:25:19 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(len(contents)), o.Size())
|
|
|
|
assert.Equal(t, urlFileName, o.Remote())
|
|
|
|
|
|
|
|
// Check auto file naming when url without file name
|
2020-04-19 19:40:17 +08:00
|
|
|
o, err = operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, true, false)
|
2019-09-04 00:25:19 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2019-08-06 02:20:50 +08:00
|
|
|
// Check an error is returned for a 404
|
|
|
|
status = http.StatusNotFound
|
2020-04-19 19:40:17 +08:00
|
|
|
o, err = operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, false, false)
|
2019-08-06 02:20:50 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "Not Found")
|
|
|
|
assert.Nil(t, o)
|
|
|
|
status = 0
|
|
|
|
|
2019-03-09 04:33:22 +08:00
|
|
|
// check when reading from unverified HTTPS server
|
|
|
|
fs.Config.InsecureSkipVerify = true
|
|
|
|
fshttp.ResetTransport()
|
|
|
|
defer func() {
|
|
|
|
fs.Config.InsecureSkipVerify = false
|
|
|
|
fshttp.ResetTransport()
|
|
|
|
}()
|
|
|
|
tss := httptest.NewTLSServer(handler)
|
|
|
|
defer tss.Close()
|
|
|
|
|
2020-04-19 19:40:17 +08:00
|
|
|
o, err = operations.CopyURL(context.Background(), r.Fremote, "file2", tss.URL, false, false)
|
2019-03-09 04:33:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(len(contents)), o.Size())
|
2019-09-04 00:25:19 +08:00
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2, fstest.NewItem(urlFileName, contents, t1)}, nil, fs.ModTimeNotSupported)
|
2018-11-03 01:29:57 +08:00
|
|
|
}
|
|
|
|
|
2019-12-19 01:02:13 +08:00
|
|
|
func TestCopyURLToWriter(t *testing.T) {
|
|
|
|
contents := "file contents\n"
|
|
|
|
|
|
|
|
// check when reading from regular HTTP server
|
|
|
|
status := 0
|
|
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if status != 0 {
|
|
|
|
http.Error(w, "an error ocurred", status)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err := w.Write([]byte(contents))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
ts := httptest.NewServer(handler)
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
// test normal fetch
|
|
|
|
var buf bytes.Buffer
|
|
|
|
err := operations.CopyURLToWriter(context.Background(), ts.URL, &buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, contents, buf.String())
|
|
|
|
|
|
|
|
// test fetch with error
|
|
|
|
status = http.StatusNotFound
|
|
|
|
buf.Reset()
|
|
|
|
err = operations.CopyURLToWriter(context.Background(), ts.URL, &buf)
|
|
|
|
require.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "Not Found")
|
|
|
|
assert.Equal(t, 0, len(buf.String()))
|
|
|
|
}
|
|
|
|
|
2016-10-24 00:34:17 +08:00
|
|
|
func TestMoveFile(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-10-24 00:34:17 +08:00
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("file1", "file1 contents", t1)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2016-10-24 00:34:17 +08:00
|
|
|
|
|
|
|
file2 := file1
|
|
|
|
file2.Path = "sub/file2"
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
2016-10-24 00:34:17 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-10-24 00:34:17 +08:00
|
|
|
|
|
|
|
r.WriteFile("file1", "file1 contents", t1)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2016-10-24 00:34:17 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
2016-10-24 00:34:17 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2017-05-27 23:30:26 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.MoveFile(context.Background(), r.Fremote, r.Fremote, file2.Path, file2.Path)
|
2017-05-27 23:30:26 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-10-24 00:34:17 +08:00
|
|
|
}
|
|
|
|
|
2019-06-10 18:01:13 +08:00
|
|
|
func TestCaseInsensitiveMoveFile(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
if !r.Fremote.Features().CaseInsensitive {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
file1 := r.WriteFile("file1", "file1 contents", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
|
|
|
file2 := file1
|
|
|
|
file2.Path = "sub/file2"
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
2019-06-10 18:01:13 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
|
|
|
|
|
|
|
r.WriteFile("file1", "file1 contents", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
2019-06-10 18:01:13 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
|
|
|
|
|
|
|
file2Capitalized := file2
|
|
|
|
file2Capitalized.Path = "sub/File2"
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.MoveFile(context.Background(), r.Fremote, r.Fremote, file2Capitalized.Path, file2.Path)
|
2019-06-10 18:01:13 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2Capitalized)
|
|
|
|
}
|
|
|
|
|
2019-05-23 20:17:16 +08:00
|
|
|
func TestMoveFileBackupDir(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2019-07-02 19:22:29 +08:00
|
|
|
if !operations.CanServerSideMove(r.Fremote) {
|
2020-10-14 05:43:40 +08:00
|
|
|
t.Skip("Skipping test as remote does not support server-side move or copy")
|
2019-07-02 17:46:49 +08:00
|
|
|
}
|
2019-05-23 20:17:16 +08:00
|
|
|
|
|
|
|
oldBackupDir := fs.Config.BackupDir
|
|
|
|
fs.Config.BackupDir = r.FremoteName + "/backup"
|
|
|
|
defer func() {
|
|
|
|
fs.Config.BackupDir = oldBackupDir
|
|
|
|
}()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("dst/file1", "file1 contents", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
file1old := r.WriteObject(context.Background(), "dst/file1", "file1 contents old", t1)
|
2019-05-23 20:17:16 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1old)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.MoveFile(context.Background(), r.Fremote, r.Flocal, file1.Path, file1.Path)
|
2019-05-23 20:17:16 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckItems(t, r.Flocal)
|
|
|
|
file1old.Path = "backup/dst/file1"
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1old, file1)
|
|
|
|
}
|
|
|
|
|
2016-10-24 00:34:17 +08:00
|
|
|
func TestCopyFile(t *testing.T) {
|
2017-10-29 20:23:10 +08:00
|
|
|
r := fstest.NewRun(t)
|
2016-10-24 00:34:17 +08:00
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("file1", "file1 contents", t1)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
2016-10-24 00:34:17 +08:00
|
|
|
|
|
|
|
file2 := file1
|
|
|
|
file2.Path = "sub/file2"
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.CopyFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
2016-10-24 00:34:17 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-10-24 00:34:17 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.CopyFile(context.Background(), r.Fremote, r.Flocal, file2.Path, file1.Path)
|
2016-10-24 00:34:17 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2017-05-27 23:30:26 +08:00
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err = operations.CopyFile(context.Background(), r.Fremote, r.Fremote, file2.Path, file2.Path)
|
2017-05-27 23:30:26 +08:00
|
|
|
require.NoError(t, err)
|
2017-10-29 20:23:10 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2)
|
2016-10-24 00:34:17 +08:00
|
|
|
}
|
2017-01-11 22:59:53 +08:00
|
|
|
|
2019-05-23 20:17:16 +08:00
|
|
|
func TestCopyFileBackupDir(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2019-07-02 19:22:29 +08:00
|
|
|
if !operations.CanServerSideMove(r.Fremote) {
|
2020-10-14 05:43:40 +08:00
|
|
|
t.Skip("Skipping test as remote does not support server-side move or copy")
|
2019-07-02 17:46:49 +08:00
|
|
|
}
|
2019-05-23 20:17:16 +08:00
|
|
|
|
|
|
|
oldBackupDir := fs.Config.BackupDir
|
|
|
|
fs.Config.BackupDir = r.FremoteName + "/backup"
|
|
|
|
defer func() {
|
|
|
|
fs.Config.BackupDir = oldBackupDir
|
|
|
|
}()
|
|
|
|
|
|
|
|
file1 := r.WriteFile("dst/file1", "file1 contents", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
file1old := r.WriteObject(context.Background(), "dst/file1", "file1 contents old", t1)
|
2019-05-23 20:17:16 +08:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1old)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
err := operations.CopyFile(context.Background(), r.Fremote, r.Flocal, file1.Path, file1.Path)
|
2019-05-23 20:17:16 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
file1old.Path = "backup/dst/file1"
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1old, file1)
|
|
|
|
}
|
|
|
|
|
2019-07-08 09:02:53 +08:00
|
|
|
// Test with CompareDest set
|
|
|
|
func TestCopyFileCompareDest(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
fs.Config.CompareDest = r.FremoteName + "/CompareDest"
|
|
|
|
defer func() {
|
|
|
|
fs.Config.CompareDest = ""
|
|
|
|
}()
|
|
|
|
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check empty dest, empty compare
|
|
|
|
file1 := r.WriteFile("one", "one", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file1.Path, file1.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1dst := file1
|
|
|
|
file1dst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
|
|
|
|
// check old dest, empty compare
|
|
|
|
file1b := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1b)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file1b.Path, file1b.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1bdst := file1b
|
|
|
|
file1bdst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1bdst)
|
|
|
|
|
|
|
|
// check old dest, new compare
|
|
|
|
file3 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "CompareDest/one", "onet2", t2)
|
|
|
|
file1c := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file1c.Path, file1c.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
|
|
|
|
// check empty dest, new compare
|
|
|
|
file4 := r.WriteObject(context.Background(), "CompareDest/two", "two", t2)
|
|
|
|
file5 := r.WriteFile("two", "two", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file5.Path, file5.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
|
|
|
|
// check new dest, new compare
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file5.Path, file5.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
|
|
|
|
// check empty dest, old compare
|
|
|
|
file5b := r.WriteFile("two", "twot3", t3)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5b)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file5b.Path, file5b.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file5bdst := file5b
|
|
|
|
file5bdst.Path = "dst/two"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3, file4, file5bdst)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with CopyDest set
|
|
|
|
func TestCopyFileCopyDest(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
if r.Fremote.Features().Copy == nil {
|
2020-10-14 05:43:40 +08:00
|
|
|
t.Skip("Skipping test as remote does not support server-side copy")
|
2019-07-08 09:02:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fs.Config.CopyDest = r.FremoteName + "/CopyDest"
|
|
|
|
defer func() {
|
|
|
|
fs.Config.CopyDest = ""
|
|
|
|
}()
|
|
|
|
|
|
|
|
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check empty dest, empty copy
|
|
|
|
file1 := r.WriteFile("one", "one", t1)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file1.Path, file1.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1dst := file1
|
|
|
|
file1dst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
|
|
|
|
// check old dest, empty copy
|
|
|
|
file1b := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1dst)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1b)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file1b.Path, file1b.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1bdst := file1b
|
|
|
|
file1bdst.Path = "dst/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1bdst)
|
|
|
|
|
|
|
|
// check old dest, new copy, backup-dir
|
|
|
|
|
|
|
|
fs.Config.BackupDir = r.FremoteName + "/BackupDir"
|
|
|
|
|
|
|
|
file3 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "CopyDest/one", "onet2", t2)
|
|
|
|
file1c := r.WriteFile("one", "onet2", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file3)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file1c.Path, file1c.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file2dst := file2
|
|
|
|
file2dst.Path = "dst/one"
|
|
|
|
file3.Path = "BackupDir/one"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3)
|
|
|
|
fs.Config.BackupDir = ""
|
|
|
|
|
|
|
|
// check empty dest, new copy
|
|
|
|
file4 := r.WriteObject(context.Background(), "CopyDest/two", "two", t2)
|
|
|
|
file5 := r.WriteFile("two", "two", t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file5.Path, file5.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file4dst := file4
|
|
|
|
file4dst.Path = "dst/two"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst)
|
|
|
|
|
|
|
|
// check new dest, new copy
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file5.Path, file5.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst)
|
|
|
|
|
|
|
|
// check empty dest, old copy
|
|
|
|
file6 := r.WriteObject(context.Background(), "CopyDest/three", "three", t2)
|
|
|
|
file7 := r.WriteFile("three", "threet3", t3)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6)
|
|
|
|
fstest.CheckItems(t, r.Flocal, file1c, file5, file7)
|
|
|
|
|
|
|
|
err = operations.CopyFile(context.Background(), fdst, r.Flocal, file7.Path, file7.Path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file7dst := file7
|
|
|
|
file7dst.Path = "dst/three"
|
|
|
|
|
|
|
|
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6, file7dst)
|
|
|
|
}
|
|
|
|
|
2017-01-11 22:59:53 +08:00
|
|
|
// testFsInfo is for unit testing fs.Info
|
|
|
|
type testFsInfo struct {
|
|
|
|
name string
|
|
|
|
root string
|
|
|
|
stringVal string
|
|
|
|
precision time.Duration
|
2018-01-13 00:30:54 +08:00
|
|
|
hashes hash.Set
|
2017-01-14 01:21:47 +08:00
|
|
|
features fs.Features
|
2017-01-11 22:59:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name of the remote (as passed into NewFs)
|
|
|
|
func (i *testFsInfo) Name() string { return i.name }
|
|
|
|
|
|
|
|
// Root of the remote (as passed into NewFs)
|
|
|
|
func (i *testFsInfo) Root() string { return i.root }
|
|
|
|
|
|
|
|
// String returns a description of the FS
|
|
|
|
func (i *testFsInfo) String() string { return i.stringVal }
|
|
|
|
|
|
|
|
// Precision of the ModTimes in this Fs
|
|
|
|
func (i *testFsInfo) Precision() time.Duration { return i.precision }
|
|
|
|
|
|
|
|
// Returns the supported hash types of the filesystem
|
2018-01-13 00:30:54 +08:00
|
|
|
func (i *testFsInfo) Hashes() hash.Set { return i.hashes }
|
2017-01-11 22:59:53 +08:00
|
|
|
|
2017-01-14 01:21:47 +08:00
|
|
|
// Returns the supported hash types of the filesystem
|
|
|
|
func (i *testFsInfo) Features() *fs.Features { return &i.features }
|
|
|
|
|
2017-01-11 22:59:53 +08:00
|
|
|
func TestSameConfig(t *testing.T) {
|
|
|
|
a := &testFsInfo{name: "name", root: "root"}
|
|
|
|
for _, test := range []struct {
|
|
|
|
name string
|
|
|
|
root string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{"name", "root", true},
|
|
|
|
{"name", "rooty", true},
|
|
|
|
{"namey", "root", false},
|
|
|
|
{"namey", "roott", false},
|
|
|
|
} {
|
|
|
|
b := &testFsInfo{name: test.name, root: test.root}
|
2018-01-13 00:30:54 +08:00
|
|
|
actual := operations.SameConfig(a, b)
|
2017-01-11 22:59:53 +08:00
|
|
|
assert.Equal(t, test.expected, actual)
|
2018-01-13 00:30:54 +08:00
|
|
|
actual = operations.SameConfig(b, a)
|
2017-01-11 22:59:53 +08:00
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSame(t *testing.T) {
|
|
|
|
a := &testFsInfo{name: "name", root: "root"}
|
|
|
|
for _, test := range []struct {
|
|
|
|
name string
|
|
|
|
root string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{"name", "root", true},
|
|
|
|
{"name", "rooty", false},
|
|
|
|
{"namey", "root", false},
|
|
|
|
{"namey", "roott", false},
|
|
|
|
} {
|
|
|
|
b := &testFsInfo{name: test.name, root: test.root}
|
2018-01-13 00:30:54 +08:00
|
|
|
actual := operations.Same(a, b)
|
2017-01-11 22:59:53 +08:00
|
|
|
assert.Equal(t, test.expected, actual)
|
2018-01-13 00:30:54 +08:00
|
|
|
actual = operations.Same(b, a)
|
2017-01-11 22:59:53 +08:00
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOverlapping(t *testing.T) {
|
|
|
|
a := &testFsInfo{name: "name", root: "root"}
|
2019-02-28 19:39:32 +08:00
|
|
|
slash := string(os.PathSeparator) // native path separator
|
2017-01-11 22:59:53 +08:00
|
|
|
for _, test := range []struct {
|
|
|
|
name string
|
|
|
|
root string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{"name", "root", true},
|
|
|
|
{"namey", "root", false},
|
|
|
|
{"name", "rooty", false},
|
|
|
|
{"namey", "rooty", false},
|
|
|
|
{"name", "roo", false},
|
|
|
|
{"name", "root/toot", true},
|
|
|
|
{"name", "root/toot/", true},
|
2019-02-28 19:39:32 +08:00
|
|
|
{"name", "root" + slash + "toot", true},
|
|
|
|
{"name", "root" + slash + "toot" + slash, true},
|
2017-01-11 22:59:53 +08:00
|
|
|
{"name", "", true},
|
|
|
|
{"name", "/", true},
|
|
|
|
} {
|
|
|
|
b := &testFsInfo{name: test.name, root: test.root}
|
|
|
|
what := fmt.Sprintf("(%q,%q) vs (%q,%q)", a.name, a.root, b.name, b.root)
|
2018-01-13 00:30:54 +08:00
|
|
|
actual := operations.Overlapping(a, b)
|
2017-01-11 22:59:53 +08:00
|
|
|
assert.Equal(t, test.expected, actual, what)
|
2018-01-13 00:30:54 +08:00
|
|
|
actual = operations.Overlapping(b, a)
|
2017-01-11 22:59:53 +08:00
|
|
|
assert.Equal(t, test.expected, actual, what)
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 19:00:05 +08:00
|
|
|
|
2018-01-06 22:39:31 +08:00
|
|
|
func TestListFormat(t *testing.T) {
|
2019-02-14 16:45:03 +08:00
|
|
|
item0 := &operations.ListJSONItem{
|
|
|
|
Path: "a",
|
|
|
|
Name: "a",
|
|
|
|
Encrypted: "encryptedFileName",
|
|
|
|
Size: 1,
|
|
|
|
MimeType: "application/octet-stream",
|
|
|
|
ModTime: operations.Timestamp{
|
|
|
|
When: t1,
|
|
|
|
Format: "2006-01-02T15:04:05.000000000Z07:00"},
|
|
|
|
IsDir: false,
|
|
|
|
Hashes: map[string]string{
|
|
|
|
"MD5": "0cc175b9c0f1b6a831c399e269772661",
|
|
|
|
"SHA-1": "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8",
|
|
|
|
"DropboxHash": "bf5d3affb73efd2ec6c36ad3112dd933efed63c4e1cbffcfa88e2759c144f2d8",
|
|
|
|
"QuickXorHash": "6100000000000000000000000100000000000000"},
|
|
|
|
ID: "fileID",
|
|
|
|
OrigID: "fileOrigID",
|
|
|
|
}
|
2018-01-06 22:39:31 +08:00
|
|
|
|
2019-02-14 16:45:03 +08:00
|
|
|
item1 := &operations.ListJSONItem{
|
|
|
|
Path: "subdir",
|
|
|
|
Name: "subdir",
|
|
|
|
Encrypted: "encryptedDirName",
|
|
|
|
Size: -1,
|
|
|
|
MimeType: "inode/directory",
|
|
|
|
ModTime: operations.Timestamp{
|
|
|
|
When: t2,
|
|
|
|
Format: "2006-01-02T15:04:05.000000000Z07:00"},
|
|
|
|
IsDir: true,
|
|
|
|
Hashes: map[string]string(nil),
|
|
|
|
ID: "dirID",
|
|
|
|
OrigID: "dirOrigID",
|
|
|
|
}
|
2018-01-06 22:39:31 +08:00
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
var list operations.ListFormat
|
2018-01-06 22:39:31 +08:00
|
|
|
list.AddPath()
|
|
|
|
list.SetDirSlash(false)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "subdir", list.Format(item1))
|
2018-01-06 22:39:31 +08:00
|
|
|
|
|
|
|
list.SetDirSlash(true)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "subdir/", list.Format(item1))
|
2018-01-06 22:39:31 +08:00
|
|
|
|
|
|
|
list.SetOutput(nil)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "", list.Format(item1))
|
2018-01-06 22:39:31 +08:00
|
|
|
|
2019-02-14 16:45:03 +08:00
|
|
|
list.AppendOutput(func(item *operations.ListJSONItem) string { return "a" })
|
|
|
|
list.AppendOutput(func(item *operations.ListJSONItem) string { return "b" })
|
|
|
|
assert.Equal(t, "ab", list.Format(item1))
|
2018-01-06 22:39:31 +08:00
|
|
|
list.SetSeparator(":::")
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "a:::b", list.Format(item1))
|
2018-01-06 22:39:31 +08:00
|
|
|
|
|
|
|
list.SetOutput(nil)
|
|
|
|
list.AddModTime()
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, t1.Local().Format("2006-01-02 15:04:05"), list.Format(item0))
|
2018-01-06 22:39:31 +08:00
|
|
|
|
2018-05-13 16:18:08 +08:00
|
|
|
list.SetOutput(nil)
|
2019-02-14 16:45:03 +08:00
|
|
|
list.SetSeparator("|")
|
2018-05-13 16:18:08 +08:00
|
|
|
list.AddID()
|
2019-02-14 16:45:03 +08:00
|
|
|
list.AddOrigID()
|
|
|
|
assert.Equal(t, "fileID|fileOrigID", list.Format(item0))
|
|
|
|
assert.Equal(t, "dirID|dirOrigID", list.Format(item1))
|
2018-05-13 16:18:08 +08:00
|
|
|
|
2018-05-13 17:37:25 +08:00
|
|
|
list.SetOutput(nil)
|
|
|
|
list.AddMimeType()
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Contains(t, list.Format(item0), "/")
|
|
|
|
assert.Equal(t, "inode/directory", list.Format(item1))
|
2018-05-13 17:37:25 +08:00
|
|
|
|
2018-06-03 17:42:34 +08:00
|
|
|
list.SetOutput(nil)
|
|
|
|
list.AddPath()
|
|
|
|
list.SetAbsolute(true)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "/a", list.Format(item0))
|
2018-06-03 17:42:34 +08:00
|
|
|
list.SetAbsolute(false)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "a", list.Format(item0))
|
2018-06-03 17:42:34 +08:00
|
|
|
|
2018-01-06 22:39:31 +08:00
|
|
|
list.SetOutput(nil)
|
|
|
|
list.AddSize()
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "1", list.Format(item0))
|
2018-01-06 22:39:31 +08:00
|
|
|
|
|
|
|
list.AddPath()
|
|
|
|
list.AddModTime()
|
|
|
|
list.SetDirSlash(true)
|
|
|
|
list.SetSeparator("__SEP__")
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "1__SEP__a__SEP__"+t1.Local().Format("2006-01-02 15:04:05"), list.Format(item0))
|
|
|
|
assert.Equal(t, "-1__SEP__subdir/__SEP__"+t2.Local().Format("2006-01-02 15:04:05"), list.Format(item1))
|
2018-01-07 01:53:37 +08:00
|
|
|
|
|
|
|
for _, test := range []struct {
|
2018-01-13 00:30:54 +08:00
|
|
|
ht hash.Type
|
2018-01-07 01:53:37 +08:00
|
|
|
want string
|
|
|
|
}{
|
2018-01-19 04:27:52 +08:00
|
|
|
{hash.MD5, "0cc175b9c0f1b6a831c399e269772661"},
|
|
|
|
{hash.SHA1, "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"},
|
2018-01-07 01:53:37 +08:00
|
|
|
} {
|
|
|
|
list.SetOutput(nil)
|
|
|
|
list.AddHash(test.ht)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, test.want, list.Format(item0))
|
2018-01-07 01:53:37 +08:00
|
|
|
}
|
2018-05-13 19:15:05 +08:00
|
|
|
|
|
|
|
list.SetOutput(nil)
|
|
|
|
list.SetSeparator("|")
|
|
|
|
list.SetCSV(true)
|
|
|
|
list.AddSize()
|
|
|
|
list.AddPath()
|
|
|
|
list.AddModTime()
|
|
|
|
list.SetDirSlash(true)
|
2019-02-14 16:45:03 +08:00
|
|
|
assert.Equal(t, "1|a|"+t1.Local().Format("2006-01-02 15:04:05"), list.Format(item0))
|
|
|
|
assert.Equal(t, "-1|subdir/|"+t2.Local().Format("2006-01-02 15:04:05"), list.Format(item1))
|
|
|
|
|
|
|
|
list.SetOutput(nil)
|
|
|
|
list.SetSeparator("|")
|
|
|
|
list.AddPath()
|
|
|
|
list.AddEncrypted()
|
|
|
|
assert.Equal(t, "a|encryptedFileName", list.Format(item0))
|
|
|
|
assert.Equal(t, "subdir/|encryptedDirName/", list.Format(item1))
|
2018-05-13 19:15:05 +08:00
|
|
|
|
2018-01-06 22:39:31 +08:00
|
|
|
}
|
2019-01-16 00:43:55 +08:00
|
|
|
|
|
|
|
func TestDirMove(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2019-01-16 00:43:55 +08:00
|
|
|
|
|
|
|
// Make some files and dirs
|
2019-06-17 16:34:30 +08:00
|
|
|
r.ForceMkdir(context.Background(), r.Fremote)
|
2019-01-16 00:43:55 +08:00
|
|
|
files := []fstest.Item{
|
2019-06-17 16:34:30 +08:00
|
|
|
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),
|
2019-01-16 00:43:55 +08:00
|
|
|
}
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B2"))
|
|
|
|
require.NoError(t, operations.Mkdir(context.Background(), r.Fremote, "A1/B1/C3"))
|
2019-01-16 00:43:55 +08:00
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
files,
|
|
|
|
[]string{
|
|
|
|
"A1",
|
|
|
|
"A1/B1",
|
|
|
|
"A1/B2",
|
|
|
|
"A1/B1/C1",
|
|
|
|
"A1/B1/C2",
|
|
|
|
"A1/B1/C3",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.DirMove(context.Background(), r.Fremote, "A1", "A2"))
|
2019-01-16 00:43:55 +08:00
|
|
|
|
|
|
|
for i := range files {
|
|
|
|
files[i].Path = strings.Replace(files[i].Path, "A1/", "A2/", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
files,
|
|
|
|
[]string{
|
|
|
|
"A2",
|
|
|
|
"A2/B1",
|
|
|
|
"A2/B2",
|
|
|
|
"A2/B1/C1",
|
|
|
|
"A2/B1/C2",
|
|
|
|
"A2/B1/C3",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Disable DirMove
|
|
|
|
features := r.Fremote.Features()
|
|
|
|
oldDirMove := features.DirMove
|
|
|
|
features.DirMove = nil
|
|
|
|
defer func() {
|
|
|
|
features.DirMove = oldDirMove
|
|
|
|
}()
|
|
|
|
|
2019-06-17 16:34:30 +08:00
|
|
|
require.NoError(t, operations.DirMove(context.Background(), r.Fremote, "A2", "A3"))
|
2019-01-16 00:43:55 +08:00
|
|
|
|
|
|
|
for i := range files {
|
|
|
|
files[i].Path = strings.Replace(files[i].Path, "A2/", "A3/", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fstest.CheckListingWithPrecision(
|
|
|
|
t,
|
|
|
|
r.Fremote,
|
|
|
|
files,
|
|
|
|
[]string{
|
|
|
|
"A3",
|
|
|
|
"A3/B1",
|
|
|
|
"A3/B2",
|
|
|
|
"A3/B1/C1",
|
|
|
|
"A3/B1/C2",
|
|
|
|
"A3/B1/C3",
|
|
|
|
},
|
|
|
|
fs.GetModifyWindow(r.Fremote),
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
2019-06-08 16:19:07 +08:00
|
|
|
|
|
|
|
func TestGetFsInfo(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
f := r.Fremote
|
|
|
|
info := operations.GetFsInfo(f)
|
|
|
|
assert.Equal(t, f.Name(), info.Name)
|
|
|
|
assert.Equal(t, f.Root(), info.Root)
|
|
|
|
assert.Equal(t, f.String(), info.String)
|
|
|
|
assert.Equal(t, f.Precision(), info.Precision)
|
|
|
|
hashSet := hash.NewHashSet()
|
|
|
|
for _, hashName := range info.Hashes {
|
|
|
|
var ht hash.Type
|
|
|
|
require.NoError(t, ht.Set(hashName))
|
|
|
|
hashSet.Add(ht)
|
|
|
|
}
|
|
|
|
assert.Equal(t, f.Hashes(), hashSet)
|
|
|
|
assert.Equal(t, f.Features().Enabled(), info.Features)
|
|
|
|
}
|
2020-02-14 20:26:52 +08:00
|
|
|
|
|
|
|
func TestRcat(t *testing.T) {
|
2020-02-14 20:47:11 +08:00
|
|
|
check := func(withChecksum, ignoreChecksum bool) {
|
|
|
|
checksumBefore, ignoreChecksumBefore := fs.Config.CheckSum, fs.Config.IgnoreChecksum
|
|
|
|
fs.Config.CheckSum, fs.Config.IgnoreChecksum = withChecksum, ignoreChecksum
|
|
|
|
defer func() {
|
|
|
|
fs.Config.CheckSum, fs.Config.IgnoreChecksum = checksumBefore, ignoreChecksumBefore
|
|
|
|
}()
|
2020-02-14 20:26:52 +08:00
|
|
|
|
2020-02-14 20:47:11 +08:00
|
|
|
var prefix string
|
2020-02-14 20:26:52 +08:00
|
|
|
if withChecksum {
|
|
|
|
prefix = "with_checksum_"
|
2020-02-14 20:47:11 +08:00
|
|
|
} else {
|
|
|
|
prefix = "no_checksum_"
|
|
|
|
}
|
|
|
|
if ignoreChecksum {
|
|
|
|
prefix = "ignore_checksum_"
|
2020-02-14 20:26:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
if *fstest.SizeLimit > 0 && int64(fs.Config.StreamingUploadCutoff) > *fstest.SizeLimit {
|
|
|
|
savedCutoff := fs.Config.StreamingUploadCutoff
|
|
|
|
defer func() {
|
|
|
|
fs.Config.StreamingUploadCutoff = savedCutoff
|
|
|
|
}()
|
|
|
|
fs.Config.StreamingUploadCutoff = fs.SizeSuffix(*fstest.SizeLimit)
|
|
|
|
t.Logf("Adjust StreamingUploadCutoff to size limit %s (was %s)", fs.Config.StreamingUploadCutoff, savedCutoff)
|
|
|
|
}
|
|
|
|
|
|
|
|
fstest.CheckListing(t, r.Fremote, []fstest.Item{})
|
|
|
|
|
|
|
|
data1 := "this is some really nice test data"
|
|
|
|
path1 := prefix + "small_file_from_pipe"
|
|
|
|
|
|
|
|
data2 := string(make([]byte, fs.Config.StreamingUploadCutoff+1))
|
|
|
|
path2 := prefix + "big_file_from_pipe"
|
|
|
|
|
|
|
|
in := ioutil.NopCloser(strings.NewReader(data1))
|
|
|
|
_, err := operations.Rcat(context.Background(), r.Fremote, path1, in, t1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
in = ioutil.NopCloser(strings.NewReader(data2))
|
|
|
|
_, err = operations.Rcat(context.Background(), r.Fremote, path2, in, t2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
file1 := fstest.NewItem(path1, data1, t1)
|
|
|
|
file2 := fstest.NewItem(path2, data2, t2)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
}
|
|
|
|
|
2020-02-14 20:47:11 +08:00
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
withChecksum := (i & 1) != 0
|
|
|
|
ignoreChecksum := (i & 2) != 0
|
|
|
|
t.Run(fmt.Sprintf("withChecksum=%v,ignoreChecksum=%v", withChecksum, ignoreChecksum), func(t *testing.T) {
|
|
|
|
check(withChecksum, ignoreChecksum)
|
|
|
|
})
|
|
|
|
}
|
2020-02-14 20:26:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRcatSize(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
const body = "------------------------------------------------------------"
|
|
|
|
file1 := r.WriteFile("potato1", body, t1)
|
|
|
|
file2 := r.WriteFile("potato2", body, t2)
|
|
|
|
// Test with known length
|
|
|
|
bodyReader := ioutil.NopCloser(strings.NewReader(body))
|
|
|
|
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())
|
|
|
|
|
|
|
|
// Test with unknown length
|
|
|
|
bodyReader = ioutil.NopCloser(strings.NewReader(body)) // reset Reader
|
|
|
|
ioutil.NopCloser(strings.NewReader(body))
|
|
|
|
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())
|
|
|
|
|
|
|
|
// Check files exist
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file2)
|
|
|
|
}
|
2019-10-31 03:23:17 +08:00
|
|
|
|
|
|
|
func TestCopyFileMaxTransfer(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
old := fs.Config.MaxTransfer
|
2020-02-26 01:03:21 +08:00
|
|
|
oldMode := fs.Config.CutoffMode
|
2019-10-31 03:23:17 +08:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
fs.Config.MaxTransfer = old
|
2020-02-26 01:03:21 +08:00
|
|
|
fs.Config.CutoffMode = oldMode
|
2019-10-31 03:23:17 +08:00
|
|
|
accounting.Stats(context.Background()).ResetCounters()
|
|
|
|
}()
|
|
|
|
|
2020-03-14 00:20:15 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2020-03-15 19:13:27 +08:00
|
|
|
const sizeCutoff = 2048
|
2020-04-23 17:39:06 +08:00
|
|
|
file1 := r.WriteFile("TestCopyFileMaxTransfer/file1", "file1 contents", t1)
|
|
|
|
file2 := r.WriteFile("TestCopyFileMaxTransfer/file2", "file2 contents"+random.String(sizeCutoff), t2)
|
|
|
|
file3 := r.WriteFile("TestCopyFileMaxTransfer/file3", "file3 contents"+random.String(sizeCutoff), t2)
|
|
|
|
file4 := r.WriteFile("TestCopyFileMaxTransfer/file4", "file4 contents"+random.String(sizeCutoff), t2)
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// Cutoff mode: Hard
|
2020-03-15 19:13:27 +08:00
|
|
|
fs.Config.MaxTransfer = sizeCutoff
|
2020-02-26 01:03:21 +08:00
|
|
|
fs.Config.CutoffMode = fs.CutoffModeHard
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// file1: Show a small file gets transferred OK
|
|
|
|
accounting.Stats(ctx).ResetCounters()
|
|
|
|
err := operations.CopyFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path)
|
2019-10-31 03:23:17 +08:00
|
|
|
require.NoError(t, err)
|
2020-04-23 17:39:06 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// file2: show a large file does not get transferred
|
2020-03-14 00:20:15 +08:00
|
|
|
accounting.Stats(ctx).ResetCounters()
|
2020-04-23 17:39:06 +08:00
|
|
|
err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file2.Path)
|
|
|
|
require.NotNil(t, err, "Did not get expected max transfer limit error")
|
2020-02-26 01:03:21 +08:00
|
|
|
assert.Contains(t, err.Error(), "Max transfer limit reached")
|
2019-10-31 03:23:17 +08:00
|
|
|
assert.True(t, fserrors.IsFatalError(err))
|
2020-04-23 17:39:06 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// Cutoff mode: Cautious
|
2020-02-26 01:03:21 +08:00
|
|
|
fs.Config.CutoffMode = fs.CutoffModeCautious
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// file3: show a large file does not get transferred
|
|
|
|
accounting.Stats(ctx).ResetCounters()
|
|
|
|
err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file3.Path, file3.Path)
|
2020-03-14 00:20:15 +08:00
|
|
|
require.NotNil(t, err)
|
2020-02-26 01:03:21 +08:00
|
|
|
assert.Contains(t, err.Error(), "Max transfer limit reached")
|
2020-09-09 19:53:21 +08:00
|
|
|
assert.True(t, fserrors.IsNoRetryError(err))
|
2020-04-23 17:39:06 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-03-16 22:05:05 +08:00
|
|
|
if strings.HasPrefix(r.Fremote.Name(), "TestChunker") {
|
|
|
|
t.Log("skipping remainder of test for chunker as it involves multiple transfers")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// Cutoff mode: Soft
|
2020-02-26 01:03:21 +08:00
|
|
|
fs.Config.CutoffMode = fs.CutoffModeSoft
|
2019-10-31 03:23:17 +08:00
|
|
|
|
2020-04-23 17:39:06 +08:00
|
|
|
// file4: show a large file does get transferred this time
|
|
|
|
accounting.Stats(ctx).ResetCounters()
|
|
|
|
err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file4.Path, file4.Path)
|
2019-10-31 03:23:17 +08:00
|
|
|
require.NoError(t, err)
|
2020-04-23 17:39:06 +08:00
|
|
|
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4)
|
|
|
|
fstest.CheckItems(t, r.Fremote, file1, file4)
|
2019-10-31 03:23:17 +08:00
|
|
|
}
|