Skip to content

Commit

Permalink
fix(checksum): fix single line checksum files
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Oct 26, 2024
1 parent 91f2960 commit b93c743
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/checksum/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
}
Expand Down

0 comments on commit b93c743

Please sign in to comment.