コード例 #1
0
ファイル: sync_test.go プロジェクト: marcopaganini/rclone
// Now without dry run
func TestCopy(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteFile("sub dir/hello world", "hello world", t1)

	err := fs.CopyDir(r.fremote, r.flocal)
	require.NoError(t, err)

	fstest.CheckItems(t, r.flocal, file1)
	fstest.CheckItems(t, r.fremote, file1)
}
コード例 #2
0
// Check the copy downloading a file
func TestCopyRedownload(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteObject("sub dir/hello world", "hello world", t1)
	fstest.CheckItems(t, r.fremote, file1)

	err := fs.CopyDir(r.flocal, r.fremote)
	if err != nil {
		t.Fatalf("Copy failed: %v", err)
	}

	fstest.CheckItems(t, r.flocal, file1)
}
コード例 #3
0
ファイル: operations_test.go プロジェクト: vlinhd11/rclone
// Now without dry run
func TestCopy(t *testing.T) {
	err := fs.CopyDir(fremote, flocal)
	if err != nil {
		t.Fatalf("Copy failed: %v", err)
	}

	items := []fstest.Item{
		{Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
	}

	fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
	fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
}
コード例 #4
0
ファイル: sync_test.go プロジェクト: ncw/rclone
// Check dry run is working
func TestCopyWithDryRun(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
	r.Mkdir(r.fremote)

	fs.Config.DryRun = true
	err := fs.CopyDir(r.fremote, r.flocal)
	fs.Config.DryRun = false
	require.NoError(t, err)

	fstest.CheckItems(t, r.flocal, file1)
	fstest.CheckItems(t, r.fremote)
}
コード例 #5
0
// Check dry run is working
func TestCopyWithDryRun(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteFile("sub dir/hello world", "hello world", t1)

	fs.Config.DryRun = true
	err := fs.CopyDir(r.fremote, r.flocal)
	fs.Config.DryRun = false
	if err != nil {
		t.Fatalf("Copy failed: %v", err)
	}

	fstest.CheckItems(t, r.flocal, file1)
	fstest.CheckItems(t, r.fremote)
}
コード例 #6
0
ファイル: sync_test.go プロジェクト: marcopaganini/rclone
// Test a server side copy if possible, or the backup path if not
func TestServerSideCopy(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteObject("sub dir/hello world", "hello world", t1)
	fstest.CheckItems(t, r.fremote, file1)

	fremoteCopy, _, finaliseCopy, err := fstest.RandomRemote(*RemoteName, *SubDir)
	require.NoError(t, err)
	defer finaliseCopy()
	t.Logf("Server side copy (if possible) %v -> %v", r.fremote, fremoteCopy)

	err = fs.CopyDir(fremoteCopy, r.fremote)
	require.NoError(t, err)

	fstest.CheckItems(t, fremoteCopy, file1)
}
コード例 #7
0
ファイル: sync_test.go プロジェクト: marcopaganini/rclone
// Test copy with depth
func TestCopyWithDepth(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteFile("sub dir/hello world", "hello world", t1)
	file2 := r.WriteFile("hello world2", "hello world2", t2)

	// Check the MaxDepth too
	fs.Config.MaxDepth = 1
	defer func() { fs.Config.MaxDepth = -1 }()

	err := fs.CopyDir(r.fremote, r.flocal)
	require.NoError(t, err)

	fstest.CheckItems(t, r.flocal, file1, file2)
	fstest.CheckItems(t, r.fremote, file2)
}
コード例 #8
0
ファイル: operations_test.go プロジェクト: vlinhd11/rclone
// Test a server side move if possible, or the backup path if not
func TestServerSideMove(t *testing.T) {
	fremoteMove, finaliseMove, err := fstest.RandomRemote(*RemoteName, *SubDir)
	if err != nil {
		t.Fatalf("Failed to open remote move %q: %v", *RemoteName, err)
	}
	defer finaliseMove()
	t.Logf("Server side move (if possible) %v -> %v", fremote, fremoteMove)

	// Start with a copy
	err = fs.CopyDir(fremoteMove, fremote)
	if err != nil {
		t.Fatalf("Server Side Copy failed: %v", err)
	}

	// Remove one file
	obj := fremoteMove.NewFsObject("potato2")
	if obj == nil {
		t.Fatalf("Failed to find potato2")
	}
	err = obj.Remove()
	if err != nil {
		t.Fatalf("Failed to remove object: %v", err)
	}

	// Do server side move
	err = fs.MoveDir(fremoteMove, fremote)
	if err != nil {
		t.Fatalf("Server Side Move failed: %v", err)
	}

	items := []fstest.Item{
		{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
		{Path: "potato2", Size: 60, ModTime: t1, Md5sum: "d6548b156ea68a4e003e786df99eee76"},
	}

	fstest.CheckListingWithPrecision(t, fremote, items[:0], fs.Config.ModifyWindow)
	fstest.CheckListingWithPrecision(t, fremoteMove, items, fs.Config.ModifyWindow)

	// Move it back again, dst does not exist this time
	err = fs.MoveDir(fremote, fremoteMove)
	if err != nil {
		t.Fatalf("Server Side Move 2 failed: %v", err)
	}

	fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
	fstest.CheckListingWithPrecision(t, fremoteMove, items[:0], fs.Config.ModifyWindow)
}
コード例 #9
0
// Test a server side copy if possible, or the backup path if not
func TestServerSideCopy(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()
	file1 := r.WriteObject("sub dir/hello world", "hello world", t1)
	fstest.CheckItems(t, r.fremote, file1)

	fremoteCopy, finaliseCopy, err := fstest.RandomRemote(*RemoteName, *SubDir)
	if err != nil {
		t.Fatalf("Failed to open remote copy %q: %v", *RemoteName, err)
	}
	defer finaliseCopy()
	t.Logf("Server side copy (if possible) %v -> %v", r.fremote, fremoteCopy)

	err = fs.CopyDir(fremoteCopy, r.fremote)
	if err != nil {
		t.Fatalf("Server Side Copy failed: %v", err)
	}

	fstest.CheckItems(t, fremoteCopy, file1)
}
コード例 #10
0
ファイル: operations_test.go プロジェクト: vlinhd11/rclone
// Test a server side copy if possible, or the backup path if not
func TestServerSideCopy(t *testing.T) {
	fremoteCopy, finaliseCopy, err := fstest.RandomRemote(*RemoteName, *SubDir)
	if err != nil {
		t.Fatalf("Failed to open remote copy %q: %v", *RemoteName, err)
	}
	defer finaliseCopy()
	t.Logf("Server side copy (if possible) %v -> %v", fremote, fremoteCopy)

	err = fs.CopyDir(fremoteCopy, fremote)
	if err != nil {
		t.Fatalf("Server Side Copy failed: %v", err)
	}

	items := []fstest.Item{
		{Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
	}

	fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
	fstest.CheckListingWithPrecision(t, fremoteCopy, items, fs.Config.ModifyWindow)
}
コード例 #11
0
ファイル: rclone.go プロジェクト: JoeyGo23/rclone
		fmt.Fprintf(os.Stderr, "Command %s needs %d arguments maximum\n", cmd.Name, cmd.MaxArgs)
		os.Exit(1)
	}
}

// Commands is a slice of possible Command~s
var Commands = []Command{
	{
		Name:     "copy",
		ArgsHelp: "source:path dest:path",
		Help: `
        Copy the source to the destination.  Doesn't transfer
        unchanged files, testing by size and modification time or
        MD5SUM.  Doesn't delete files from the destination.`,
		Run: func(fdst, fsrc fs.Fs) error {
			return fs.CopyDir(fdst, fsrc)
		},
		MinArgs: 2,
		MaxArgs: 2,
		Retry:   true,
	},
	{
		Name:     "sync",
		ArgsHelp: "source:path dest:path",
		Help: `
        Sync the source to the destination, changing the destination
        only.  Doesn't transfer unchanged files, testing by size and
        modification time or MD5SUM.  Destination is updated to match
        source, including deleting files if necessary.  Since this can
        cause data loss, test first with the --dry-run flag.`,
		Run: func(fdst, fsrc fs.Fs) error {