mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 13:48:55 +00:00
c3958c9bd6
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com> Co-authored-by: Rhys Arkins <rhys@arkins.net> Co-authored-by: Michael Kriese <michael.kriese@visualon.de> Co-authored-by: Sergei Zharinov <zharinov@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Aleksandr Mezin <mezin.alexander@gmail.com> Co-authored-by: Jasmin Müller <9011011+jazzlyn@users.noreply.github.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { createCacheReadStream } from '../../../util/fs';
|
|
import { hashStream } from '../../../util/hash';
|
|
import { escapeRegExp, newlineRegex, regEx } from '../../../util/regex';
|
|
|
|
/**
|
|
* Parses the SHA256 checksum for a specified package path from the InRelease content.
|
|
*
|
|
* @param inReleaseContent - content of the InRelease file
|
|
* @param packagePath - path of the package file (e.g., 'contrib/binary-amd64/Packages.gz')
|
|
* @returns The SHA256 checksum if found, otherwise undefined
|
|
*/
|
|
export function parseChecksumsFromInRelease(
|
|
inReleaseContent: string,
|
|
packagePath: string,
|
|
): string | null {
|
|
const lines = inReleaseContent.split(newlineRegex);
|
|
const regex = regEx(
|
|
`([a-f0-9]{64})\\s+\\d+\\s+${escapeRegExp(packagePath)}$`,
|
|
);
|
|
|
|
for (const line of lines) {
|
|
const match = regex.exec(line);
|
|
if (match) {
|
|
return match[1];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Computes the SHA256 checksum of a specified file.
|
|
*
|
|
* @param filePath - path of the file
|
|
* @returns resolves to the SHA256 checksum
|
|
*/
|
|
export function computeFileChecksum(filePath: string): Promise<string> {
|
|
const stream = createCacheReadStream(filePath);
|
|
return hashStream(stream, 'sha256');
|
|
}
|