From 976c908a31d0d90ff935700cc38c37ea1d60912f Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 1 Feb 2022 11:01:37 +0100 Subject: [PATCH] Ignore comments in checksum files (#350) * 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. --- Dockerfile | 4 ++-- checksum.go | 5 +++++ get_test.go | 9 +++++++++ testdata/checksum-file/CHECKSUM_sha256_gpg | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 testdata/checksum-file/CHECKSUM_sha256_gpg diff --git a/Dockerfile b/Dockerfile index 7c3dd846e..c00ae3f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/checksum.go b/checksum.go index bfd515599..986b23137 100644 --- a/checksum.go +++ b/checksum.go @@ -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) { diff --git a/get_test.go b/get_test.go index 97e37c0bd..1a340c646 100644 --- a/get_test.go +++ b/get_test.go @@ -495,6 +495,7 @@ func TestGetFile_checksum_from_file(t *testing.T) { WantTransfer bool WantErr bool }{ + { "", true, @@ -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 { @@ -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 } } diff --git a/testdata/checksum-file/CHECKSUM_sha256_gpg b/testdata/checksum-file/CHECKSUM_sha256_gpg new file mode 100644 index 000000000..6ec4da877 --- /dev/null +++ b/testdata/checksum-file/CHECKSUM_sha256_gpg @@ -0,0 +1,4 @@ +---- something something + +# noisey verbose duplicate noise +SHA256 (content.txt) = 47afcdfff05a6e5d9db5f6c6df2140f04a6e7422d7ad7f6a7006a4f5a78570e4