Skip to content

Commit 18e0481

Browse files
authored
fix(cdk-assets): concurrent asset builds can leave a corrupted archive (#23677)
Resolves #23290 A very simple fix for the issue where builds with `--concurrency` specified can lead to corrupt archives. Rather than use the outputFile as the basis for the temp file name we simply use a random UUID. Please note that I was unable to run the integration tests in this instance, which are likely necessary given that this change impacts the behavior of the archiver. ---- ### All Submissions: * [ X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 23634fd commit 18e0481

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/cdk-assets/lib/private/archive.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { randomUUID } from 'crypto';
12
import { createWriteStream, promises as fs } from 'fs';
23
import * as path from 'path';
34
import * as glob from 'glob';
@@ -11,7 +12,7 @@ type Logger = (x: string) => void;
1112
export async function zipDirectory(directory: string, outputFile: string, logger: Logger): Promise<void> {
1213
// We write to a temporary file and rename at the last moment. This is so that if we are
1314
// interrupted during this process, we don't leave a half-finished file in the target location.
14-
const temporaryOutputFile = `${outputFile}._tmp`;
15+
const temporaryOutputFile = `${outputFile}.${randomUUID()}._tmp`;
1516
await writeZipFile(directory, temporaryOutputFile);
1617
await moveIntoPlace(temporaryOutputFile, outputFile, logger);
1718
}
@@ -96,4 +97,4 @@ async function pathExists(x: string) {
9697
}
9798
throw e;
9899
}
99-
}
100+
}

0 commit comments

Comments
 (0)