From 7ffed61b7ddbdcdc8192989721644c37abee9c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20Andr=C3=A9=20Elsfjordstrand=20Beck?= Date: Tue, 7 Nov 2023 16:21:39 +0100 Subject: [PATCH] fix: only use basename of filepath in generated checksum file --- internal/checksum/checksum.go | 3 ++- internal/checksum/checksum_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/checksum/checksum.go b/internal/checksum/checksum.go index cfcf9ac..f1549cc 100644 --- a/internal/checksum/checksum.go +++ b/internal/checksum/checksum.go @@ -21,6 +21,7 @@ import ( "encoding/hex" "io" "os" + "path/filepath" ) // MD5Sum returns the md5 checksum of the given file encoded as a hex string. @@ -51,7 +52,7 @@ func CreateChecksumFile(file string, checksum string, extension string) (string, } checksumFile := file + extension - content := checksum + separator + file + "\n" + content := checksum + separator + filepath.Base(file) + "\n" // Create checksum file f, err := os.Create(checksumFile) diff --git a/internal/checksum/checksum_test.go b/internal/checksum/checksum_test.go index dd3d41f..200c50f 100644 --- a/internal/checksum/checksum_test.go +++ b/internal/checksum/checksum_test.go @@ -18,6 +18,7 @@ package checksum import ( "os" + "path/filepath" "testing" ) @@ -78,7 +79,7 @@ func TestCreateChecksumFile(t *testing.T) { } got := string(b) - want := wantHash + separator + testFile + "\n" + want := wantHash + separator + filepath.Base(testFile) + "\n" if got != want { t.Errorf("expected %s, got %s", want, got)