Skip to content

Commit

Permalink
fix(debian): store both uncompressed and gzipped binary package indices
Browse files Browse the repository at this point in the history
  • Loading branch information
Nipheris committed Apr 3, 2024
1 parent b01b1e0 commit 272d980
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/deb/deb-builder.mts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class DebBuilder implements Deployer {

releaseContent += 'SHA256:\n';
for (const { address, size, name } of indices) {
releaseContent += ` ${Buffer.from(address.sha256).toString('hex')}\t${size}\t${name}`;
releaseContent += ` ${Buffer.from(address.sha256).toString('hex')}\t${size}\t${name}\n`;
}

const tempReleaseFile = path.join(this.tempPath, `Release-${randomBytes(4).toString('hex')}`);
Expand Down Expand Up @@ -231,12 +231,13 @@ export class DebBuilder implements Deployer {
unlinkSync(metaFile);
}

const packagesContentDescription = await storeStreamInCas(path.resolve(binaryPath, 'by-hash'), Readable.from(packagesContent));
binaryPackageIndices.push({
name: `${component}/${binarySubdir}/Packages.gz`,
size: packagesContentDescription.size,
address: packagesContentDescription.address,
});
const storePackageIndex = async(shortName: string, store: (root: string, stream: NodeJS.ReadableStream) => Promise<ContentDescription>) => {
const name = `${component}/${binarySubdir}/${shortName}`;
const { size, address } = await store(path.resolve(binaryPath, 'by-hash'), Readable.from(packagesContent));
binaryPackageIndices.push({ name, size, address });
};
await storePackageIndex('Packages', storeStreamInCas);
await storePackageIndex('Packages.gz', storeGzippedStreamInCas);
}),
));
});
Expand Down Expand Up @@ -264,13 +265,16 @@ interface ContentDescription {
address: ContentAddress;
}

async function storeGzippedStreamInCas(root: string, stream: NodeJS.ReadableStream): Promise<ContentDescription> {
const gzip = createGzip({ level: 9 });
const gzippedStream = new PassThrough();
await pipeline(stream, gzip, gzippedStream);
return storeStreamInCas(root, gzippedStream);
}

// https://wiki.debian.org/DebianRepository/Format#indices_acquisition_via_hashsums_.28by-hash.29
async function storeStreamInCas(root: string, stream: NodeJS.ReadableStream): Promise<ContentDescription> {
// compress and store in a buffer
const gzip = createGzip({ level: 9 });
const gzippedContent = new PassThrough();
await pipeline(stream, gzip, gzippedContent);
const contentBuffer = await buffer(gzippedContent);
const contentBuffer = await buffer(stream);

// compute a digest
const sha256Hash = createHash('sha256');
Expand Down

0 comments on commit 272d980

Please sign in to comment.