Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmds/core/shasum/shasum.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ func shasum(w io.Writer, r io.Reader, args ...string) error {
return err
}
fmt.Fprintf(w, "%x -\n", hashbytes)

} else {
file, err := os.Open(args[0])
return nil
}
for _, arg := range args {
file, err := os.Open(arg)
if err != nil {
return err
}
defer file.Close()
if hashbytes, err = shaGenerator(w, file, *algorithm); err != nil {
return err
}
fmt.Fprintf(w, "%x %s\n", hashbytes, args[0])
fmt.Fprintf(w, "%x %s\n", hashbytes, arg)
}
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions cmds/core/shasum/shasum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func TestSHASum(t *testing.T) {
algorithm: 256,
want: fmt.Sprintf("%s %s\n", "db296dd0bcb796df9b327f44104029da142c8fff313a25bd1ac7c3b7562caea9", file2.Name()),
},
{
name: "file1 and file 2 as input with sha256 sum",
args: []string{file1.Name(), file2.Name()},
algorithm: 256,
want: fmt.Sprintf("%s %s\n%s %s\n", "ae0666f161fed1a5dde998bbd0e140550d2da0db27db1d0e31e370f2bd366a57", file1.Name(),
"db296dd0bcb796df9b327f44104029da142c8fff313a25bd1ac7c3b7562caea9", file2.Name()),
},
} {
t.Run(tt.name, func(t *testing.T) {
// Setting flags
Expand Down