2022-08-28 13:21:57 +02:00
|
|
|
// Package sha1sum provides the sha1sum command.
|
2016-08-05 18:12:27 +02:00
|
|
|
package sha1sum
|
|
|
|
|
|
|
|
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: "sha1sum remote:path",
|
|
|
|
Short: `Produces an sha1sum file for all the objects in the path.`,
|
2024-08-12 18:17:46 +02:00
|
|
|
Long: `Produces an sha1sum file for all the objects in the path. This
|
2016-08-05 18:12:27 +02:00
|
|
|
is in the same format as the standard sha1sum tool produces.
|
2020-12-18 13:45:58 +01:00
|
|
|
|
|
|
|
By default, the hash is requested from the remote. If SHA-1 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 SHA-1 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 sha1sum remote:path`" + ` is equivalent
|
|
|
|
to running ` + "`rclone hashsum SHA1 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).
|
|
|
|
|
|
|
|
This command can also hash data received on STDIN, if not passing
|
|
|
|
a remote:path.
|
2016-08-05 18:12:27 +02:00
|
|
|
`,
|
2022-11-26 23:40:49 +01:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.27",
|
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.SHA1, 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.SHA1, nil, hashsum.DownloadFlag)
|
|
|
|
}
|
2020-12-18 13:45:58 +01:00
|
|
|
if hashsum.HashsumOutfile == "" {
|
|
|
|
return operations.HashLister(context.Background(), hash.SHA1, 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.SHA1, 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
|
|
|
},
|
|
|
|
}
|