2022-08-28 13:21:57 +02:00
|
|
|
// Package md5sum provides the md5sum command.
|
2016-08-05 18:12:27 +02:00
|
|
|
package md5sum
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2016-08-05 18:12:27 +02:00
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/cmd"
|
2020-12-18 13:45:58 +01:00
|
|
|
"github.com/rclone/rclone/cmd/hashsum"
|
|
|
|
"github.com/rclone/rclone/fs/hash"
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2016-08-05 18:12:27 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 17:58:11 +02:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2020-12-18 13:45:58 +01:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
2021-11-03 00:34:20 +01:00
|
|
|
hashsum.AddHashsumFlags(cmdFlags)
|
2016-08-05 18:12:27 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 17:58:11 +02:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-08-05 18:12:27 +02:00
|
|
|
Use: "md5sum remote:path",
|
|
|
|
Short: `Produces an md5sum file for all the objects in the path.`,
|
|
|
|
Long: `
|
|
|
|
Produces an md5sum file for all the objects in the path. This
|
|
|
|
is in the same format as the standard md5sum tool produces.
|
2020-12-18 13:45:58 +01:00
|
|
|
|
|
|
|
By default, the hash is requested from the remote. If MD5 is
|
|
|
|
not supported by the remote, no hash will be returned. With the
|
|
|
|
download flag, the file will be downloaded from the remote and
|
|
|
|
hashed locally enabling MD5 for any remote.
|
2021-11-03 00:34:20 +01:00
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
For other algorithms, see the [hashsum](/commands/rclone_hashsum/)
|
|
|
|
command. Running ` + "`rclone md5sum remote:path`" + ` is equivalent
|
|
|
|
to running ` + "`rclone hashsum MD5 remote:path`" + `.
|
|
|
|
|
2021-11-03 00:34:20 +01:00
|
|
|
This command can also hash data received on standard input (stdin),
|
|
|
|
by not passing a remote:path, or by passing a hyphen as remote:path
|
2022-08-14 04:56:32 +02:00
|
|
|
when there is data to read (if not, the hyphen will be treated literally,
|
2021-11-03 00:34:20 +01:00
|
|
|
as a relative path).
|
2016-08-05 18:12:27 +02:00
|
|
|
`,
|
2022-11-26 23:40:49 +01:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.02",
|
2023-07-10 19:34:10 +02:00
|
|
|
"groups": "Filter,Listing",
|
2022-11-26 23:40:49 +01:00
|
|
|
},
|
2021-11-03 00:34:20 +01:00
|
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
|
|
cmd.CheckArgs(0, 1, command, args)
|
|
|
|
if found, err := hashsum.CreateFromStdinArg(hash.MD5, args, 0); found {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-05 18:12:27 +02:00
|
|
|
fsrc := cmd.NewFsSrc(args)
|
2016-12-04 17:52:24 +01:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2021-07-07 17:34:16 +02:00
|
|
|
if hashsum.ChecksumFile != "" {
|
|
|
|
fsum, sumFile := cmd.NewFsFile(hashsum.ChecksumFile)
|
|
|
|
return operations.CheckSum(context.Background(), fsrc, fsum, sumFile, hash.MD5, nil, hashsum.DownloadFlag)
|
|
|
|
}
|
2020-12-18 13:45:58 +01:00
|
|
|
if hashsum.HashsumOutfile == "" {
|
|
|
|
return operations.HashLister(context.Background(), hash.MD5, hashsum.OutputBase64, hashsum.DownloadFlag, fsrc, nil)
|
|
|
|
}
|
|
|
|
output, close, err := hashsum.GetHashsumOutput(hashsum.HashsumOutfile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer close()
|
|
|
|
return operations.HashLister(context.Background(), hash.MD5, hashsum.OutputBase64, hashsum.DownloadFlag, fsrc, output)
|
2016-08-05 18:12:27 +02:00
|
|
|
})
|
2021-11-03 00:34:20 +01:00
|
|
|
return nil
|
2016-08-05 18:12:27 +02:00
|
|
|
},
|
|
|
|
}
|