Skip to content

Commit

Permalink
Ignore comments in checksum files (#350)
Browse files Browse the repository at this point in the history
* ignore commented lines when parsing a checksum file

* Update Dockerfile

set noninteractive mode to installation

* Update Dockerfile

pin to go 1.15, because it worked//works there; I suspect this is a "debian changed something" issue.
  • Loading branch information
azr authored Feb 1, 2022
1 parent ea452ad commit 976c908
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Dockerfile to create a go-getter container with smbclient dependency that is used by the get_smb.go tests
FROM golang:latest
FROM golang:1.15

COPY . /go-getter
WORKDIR /go-getter

RUN go mod download
RUN apt-get update
RUN apt-get -y install smbclient
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install smbclient
5 changes: 5 additions & 0 deletions checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ func (c *Client) checksumFromFile(ctx context.Context, checksumURL string, check
// for BSD type sums parseChecksumLine guesses the hashing algorithm
// by checking the length of the checksum.
func parseChecksumLine(line string) (*FileChecksum, error) {
switch line[0] {
case '#', '/', '-':
return nil, nil // skip
}
//TODO: this function will fail if we pass a checksum for a path with spaces
parts := strings.Fields(line)

switch len(parts) {
Expand Down
9 changes: 9 additions & 0 deletions get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ func TestGetFile_checksum_from_file(t *testing.T) {
WantTransfer bool
WantErr bool
}{

{
"",
true,
Expand Down Expand Up @@ -548,6 +549,13 @@ func TestGetFile_checksum_from_file(t *testing.T) {
true,
false,
},

// sha512
{
"?checksum=file:" + checksums + "/CHECKSUM_sha256_gpg",
true,
false,
},
}

for _, tc := range cases {
Expand All @@ -572,6 +580,7 @@ func TestGetFile_checksum_from_file(t *testing.T) {
testing_helper.AssertContents(t, dst, "I am a file with some content\n")
}
})
return
}
}

Expand Down
4 changes: 4 additions & 0 deletions testdata/checksum-file/CHECKSUM_sha256_gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---- something something

# noisey verbose duplicate noise
SHA256 (content.txt) = 47afcdfff05a6e5d9db5f6c6df2140f04a6e7422d7ad7f6a7006a4f5a78570e4

0 comments on commit 976c908

Please sign in to comment.