Skip to content

Commit

Permalink
by-hash initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
origin-yaropolk committed Apr 1, 2024
1 parent 051b4aa commit d111a2b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/deb/deb-builder.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createHash } from 'crypto';
import { createGzip } from 'zlib';

Check failure on line 2 in src/deb/deb-builder.mts

View workflow job for this annotation

GitHub Actions / build

Imports should be sorted alphabetically

import * as fs from 'fs';
Expand All @@ -8,6 +9,7 @@ import * as tar from 'tar';
import type { Artifact, ArtifactProvider } from '../artifact-provider.mjs';
import { createDir, execToolToFile, removeDir } from '../fs.mjs';
import type { Deployer } from '../deployer.mjs';
import { createReadStream } from 'fs';

Check failure on line 12 in src/deb/deb-builder.mts

View workflow job for this annotation

GitHub Actions / build

Imports should be sorted alphabetically

type DebRepoDistribution = string;
type DebRepoComponent = string;
Expand Down Expand Up @@ -111,6 +113,10 @@ export class DebBuilder implements Deployer {
await execToolToFile('apt-ftparchive', ['release', distributionPath], releaseFilePath, true);
await execToolToFile('gpg', ['--no-tty', '--default-key', this.config.gpgKeyName, '-abs', '-o', releaseGpgFilePath, releaseFilePath]);
await execToolToFile('gpg', ['--no-tty', '--default-key', this.config.gpgKeyName, '--clearsign', '-o', inReleaseFilePath, releaseFilePath]);

await this.handleByHash(releaseFilePath);
await this.handleByHash(releaseGpgFilePath);
await this.handleByHash(inReleaseFilePath);
}

private async dpkgScanpackages(): Promise<void> {
Expand Down Expand Up @@ -236,6 +242,7 @@ export class DebBuilder implements Deployer {
fs.writeFileSync(targetPackagesFile, packagesContent);

compressPromises.push(compressFile(targetPackagesFile));
compressPromises.push(this.handleByHash(targetPackagesFile));
});
});

Expand All @@ -254,4 +261,19 @@ export class DebBuilder implements Deployer {

return Promise.all(releasesPromises);
}

private async handleByHash(filePath: string): Promise<void> {
const byHashFileName = path.resolve(path.join(path.dirname(filePath), 'by-hash', 'SHA256', await this.sha256(filePath)));
return fs.promises.copyFile(filePath, byHashFileName);
}

private async sha256(filePath: string): Promise<string>{

Check failure on line 270 in src/deb/deb-builder.mts

View workflow job for this annotation

GitHub Actions / build

Expected 'this' to be used by class async method 'sha256'

Check failure on line 270 in src/deb/deb-builder.mts

View workflow job for this annotation

GitHub Actions / build

Async method 'sha256' has no 'await' expression

Check failure on line 270 in src/deb/deb-builder.mts

View workflow job for this annotation

GitHub Actions / build

Missing space before opening brace
return new Promise((resolve, reject) => {
const hash = createHash('sha256');
createReadStream(filePath)
.once('end', () => resolve(hash.digest('hex')))
.once('error', () => reject)
.pipe(hash);
});
}
}

0 comments on commit d111a2b

Please sign in to comment.