github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/cmd/check/check.go (about) 1 package check 2 3 import ( 4 "context" 5 6 "github.com/rclone/rclone/cmd" 7 "github.com/rclone/rclone/fs/config/flags" 8 "github.com/rclone/rclone/fs/operations" 9 "github.com/spf13/cobra" 10 ) 11 12 // Globals 13 var ( 14 download = false 15 oneway = false 16 ) 17 18 func init() { 19 cmd.Root.AddCommand(commandDefinition) 20 cmdFlags := commandDefinition.Flags() 21 flags.BoolVarP(cmdFlags, &download, "download", "", download, "Check by downloading rather than with hash.") 22 flags.BoolVarP(cmdFlags, &oneway, "one-way", "", oneway, "Check one way only, source files must exist on remote") 23 } 24 25 var commandDefinition = &cobra.Command{ 26 Use: "check source:path dest:path", 27 Short: `Checks the files in the source and destination match.`, 28 Long: ` 29 Checks the files in the source and destination match. It compares 30 sizes and hashes (MD5 or SHA1) and logs a report of files which don't 31 match. It doesn't alter the source or destination. 32 33 If you supply the --size-only flag, it will only compare the sizes not 34 the hashes as well. Use this for a quick check. 35 36 If you supply the --download flag, it will download the data from 37 both remotes and check them against each other on the fly. This can 38 be useful for remotes that don't support hashes or if you really want 39 to check all the data. 40 41 If you supply the --one-way flag, it will only check that files in source 42 match the files in destination, not the other way around. Meaning extra files in 43 destination that are not in the source will not trigger an error. 44 `, 45 Run: func(command *cobra.Command, args []string) { 46 cmd.CheckArgs(2, 2, command, args) 47 fsrc, fdst := cmd.NewFsSrcDst(args) 48 cmd.Run(false, false, command, func() error { 49 if download { 50 return operations.CheckDownload(context.Background(), fdst, fsrc, oneway) 51 } 52 return operations.Check(context.Background(), fdst, fsrc, oneway) 53 }) 54 }, 55 }