Esempio n. 1
0
func TestMoveFile(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()

	r.Mkdir(r.fremote)
	file1 := r.WriteFile("file1", "file1 contents", t1)
	fstest.CheckItems(t, r.flocal, file1)

	file2 := file1
	file2.Path = "sub/file2"

	err := fs.MoveFile(r.fremote, r.flocal, file2.Path, file1.Path)
	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)

	err = fs.MoveFile(r.fremote, r.flocal, file2.Path, file1.Path)
	require.NoError(t, err)
	fstest.CheckItems(t, r.flocal)
	fstest.CheckItems(t, r.fremote, file2)
}
Esempio n. 2
0
File: moveto.go Progetto: ncw/rclone
where src and dst are rclone paths, either remote:path or
/path/to/local or C:\windows\path\if\on\windows.

This will:

    if src is file
        move it to dst, overwriting an existing file if it exists
    if src is directory
        move it to dst, overwriting existing files if they exist
        see move command for full details

This doesn't transfer unchanged files, testing by size and
modification time or MD5SUM.  src will be deleted on successful
transfer.

**Important**: Since this can cause data loss, test first with the
--dry-run flag.
`,
	Run: func(command *cobra.Command, args []string) {
		cmd.CheckArgs(2, 2, command, args)
		fsrc, srcFileName, fdst, dstFileName := cmd.NewFsSrcDstFiles(args)

		cmd.Run(true, true, command, func() error {
			if srcFileName == "" {
				return fs.MoveDir(fdst, fsrc)
			}
			return fs.MoveFile(fdst, fsrc, dstFileName, srcFileName)
		})
	},
}