2022-08-28 11:21:57 +00:00
|
|
|
// Package sha1sum provides the sha1sum command.
|
2016-08-05 16:12:27 +00:00
|
|
|
package sha1sum
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2016-08-05 16:12:27 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd"
|
2020-12-18 12:45:58 +00:00
|
|
|
"github.com/rclone/rclone/cmd/hashsum"
|
|
|
|
"github.com/rclone/rclone/fs/hash"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2016-08-05 16:12:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 15:58:11 +00:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2020-12-18 12:45:58 +00:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
2021-11-02 23:34:20 +00:00
|
|
|
hashsum.AddHashsumFlags(cmdFlags)
|
2016-08-05 16:12:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 15:58:11 +00:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-08-05 16:12:27 +00:00
|
|
|
Use: "sha1sum remote:path",
|
|
|
|
Short: `Produces an sha1sum file for all the objects in the path.`,
|
|
|
|
Long: `
|
|
|
|
Produces an sha1sum file for all the objects in the path. This
|
|
|
|
is in the same format as the standard sha1sum tool produces.
|
2020-12-18 12:45:58 +00: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-02 23:34:20 +00:00
|
|
|
|
2022-06-19 13:51:37 +00: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-02 23:34:20 +00: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 02:56:32 +00:00
|
|
|
when there is data to read (if not, the hyphen will be treated literally,
|
2021-11-02 23:34:20 +00:00
|
|
|
as a relative path).
|
|
|
|
|
|
|
|
This command can also hash data received on STDIN, if not passing
|
|
|
|
a remote:path.
|
2016-08-05 16:12:27 +00:00
|
|
|
`,
|
2022-11-26 22:40:49 +00:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.27",
|
2023-07-10 17:34:10 +00:00
|
|
|
"groups": "Filter,Listing",
|
2022-11-26 22:40:49 +00:00
|
|
|
},
|
2021-11-02 23:34:20 +00: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 16:12:27 +00:00
|
|
|
fsrc := cmd.NewFsSrc(args)
|
2016-12-04 16:52:24 +00:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2021-07-07 15:34:16 +00: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 12:45:58 +00: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 16:12:27 +00:00
|
|
|
})
|
2021-11-02 23:34:20 +00:00
|
|
|
return nil
|
2016-08-05 16:12:27 +00:00
|
|
|
},
|
|
|
|
}
|