mirror of
https://github.com/rclone/rclone.git
synced 2024-11-27 02:34:21 +08:00
57d5de6fba
git grep -l github.com/ncw/rclone | xargs -d'\n' perl -i~ -lpe 's|github.com/ncw/rclone|github.com/rclone/rclone|g' goimports -w `find . -name \*.go`
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package hashsum
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs/hash"
|
|
"github.com/rclone/rclone/fs/operations"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefinition)
|
|
}
|
|
|
|
var commandDefinition = &cobra.Command{
|
|
Use: "hashsum <hash> remote:path",
|
|
Short: `Produces an hashsum file for all the objects in the path.`,
|
|
Long: `
|
|
Produces a hash file for all the objects in the path using the hash
|
|
named. The output is in the same format as the standard
|
|
md5sum/sha1sum tool.
|
|
|
|
Run without a hash to see the list of supported hashes, eg
|
|
|
|
$ rclone hashsum
|
|
Supported hashes are:
|
|
* MD5
|
|
* SHA-1
|
|
* DropboxHash
|
|
* QuickXorHash
|
|
|
|
Then
|
|
|
|
$ rclone hashsum MD5 remote:path
|
|
`,
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
cmd.CheckArgs(0, 2, command, args)
|
|
if len(args) == 0 {
|
|
fmt.Printf("Supported hashes are:\n")
|
|
for _, ht := range hash.Supported.Array() {
|
|
fmt.Printf(" * %v\n", ht)
|
|
}
|
|
return nil
|
|
} else if len(args) == 1 {
|
|
return errors.New("need hash type and remote")
|
|
}
|
|
var ht hash.Type
|
|
err := ht.Set(args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fsrc := cmd.NewFsSrc(args[1:])
|
|
cmd.Run(false, false, command, func() error {
|
|
return operations.HashLister(context.Background(), ht, fsrc, os.Stdout)
|
|
})
|
|
return nil
|
|
},
|
|
}
|