Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Preserve compressed artifacts when updating manifest (#71196) #71286

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ describe('manifest', () => {
});

test('Manifest can be created from list of artifacts', async () => {
const manifest = Manifest.fromArtifacts(artifacts, 'v1', ManifestConstants.INITIAL_VERSION);
const oldManifest = new Manifest(
new Date(),
ManifestConstants.SCHEMA_VERSION,
ManifestConstants.INITIAL_VERSION
);
const manifest = Manifest.fromArtifacts(artifacts, 'v1', oldManifest);
expect(
manifest.contains(
'endpoint-exceptionlist-linux-v1-5f16e5e338c53e77cfa945c17c11b175c3967bf109aa87131de41fb93b149735'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ export class Manifest {
public static fromArtifacts(
artifacts: InternalArtifactSchema[],
schemaVersion: string,
version: string
oldManifest: Manifest
): Manifest {
const manifest = new Manifest(new Date(), schemaVersion, version);
const manifest = new Manifest(new Date(), schemaVersion, oldManifest.getVersion());
artifacts.forEach((artifact) => {
manifest.addEntry(artifact);
const id = `${artifact.identifier}-${artifact.decodedSha256}`;
const existingArtifact = oldManifest.getArtifact(id);
if (existingArtifact) {
manifest.addEntry(existingArtifact);
} else {
manifest.addEntry(artifact);
}
});
return manifest;
}
Expand Down Expand Up @@ -81,8 +87,8 @@ export class Manifest {
return this.entries;
}

public getArtifact(artifactId: string): InternalArtifactSchema {
return this.entries[artifactId].getArtifact();
public getArtifact(artifactId: string): InternalArtifactSchema | undefined {
return this.entries[artifactId]?.getArtifact();
}

public diff(manifest: Manifest): ManifestDiff[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class ManifestManager {
const newManifest = Manifest.fromArtifacts(
artifacts,
ManifestConstants.SCHEMA_VERSION,
oldManifest.getVersion()
oldManifest
);

// Get diffs
Expand Down Expand Up @@ -202,6 +202,11 @@ export class ManifestManager {

for (const diff of adds) {
const artifact = snapshot.manifest.getArtifact(diff.id);
if (artifact === undefined) {
throw new Error(
`Corrupted manifest detected. Diff contained artifact ${diff.id} not in manifest.`
);
}
const compressedArtifact = await compressExceptionList(Buffer.from(artifact.body, 'base64'));
artifact.body = compressedArtifact.toString('base64');
artifact.encodedSize = compressedArtifact.byteLength;
Expand Down