From b93c7430cc90aa227ca62940a328e8b66e761f95 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Sat, 26 Oct 2024 08:57:16 -0600 Subject: [PATCH] fix(checksum): fix single line checksum files --- pkg/checksum/compare.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/checksum/compare.go b/pkg/checksum/compare.go index 5dc57bf..364e49c 100644 --- a/pkg/checksum/compare.go +++ b/pkg/checksum/compare.go @@ -28,11 +28,11 @@ func ComputeFileHash(filePath string, hashFunc func() hash.Hash) (string, error) } // CompareHashWithChecksumFile compares the computed hash of a file with the hashes in a checksum file. -func CompareHashWithChecksumFile(fileName, filePath, checksumFilePath string, hashFunc func() hash.Hash) (bool, error) { +func CompareHashWithChecksumFile(srcFilename, srcFilePath, checksumFilePath string, hashFunc func() hash.Hash) (bool, error) { log := logrus.WithField("handler", "compare-hash-with-checksum-file") // Compute the hash of the file - computedHash, err := ComputeFileHash(filePath, hashFunc) + computedHash, err := ComputeFileHash(srcFilePath, hashFunc) if err != nil { return false, err } @@ -49,18 +49,24 @@ func CompareHashWithChecksumFile(fileName, filePath, checksumFilePath string, ha for scanner.Scan() { line := scanner.Text() parts := strings.Fields(line) - if len(parts) < 2 { - log.Trace("skipping line: ", line) - continue + + var fileHash string + var hashFilename string + + if len(parts) > 1 { + fileHash = parts[0] + hashFilename = parts[1] + } else { + fileHash = parts[0] + hashFilename = srcFilename } - fileHash := parts[0] - filename := parts[1] + log.Trace("fileHash: ", fileHash) - log.Trace("filename: ", filename) + log.Trace("filename: ", hashFilename) // Rust does *(binary) for the binary name - filename = strings.TrimPrefix(filename, "*") + hashFilename = strings.TrimPrefix(hashFilename, "*") - if (filename == fileName || filepath.Base(filename) == fileName) && fileHash == computedHash { + if (hashFilename == srcFilename || filepath.Base(hashFilename) == srcFilename) && fileHash == computedHash { return true, nil } }