Skip to content

Commit

Permalink
fix(cdk-assets): concurrent asset builds can leave a corrupted archive (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
rscharer authored and rix0rrr committed Feb 6, 2023
1 parent 0b20bc5 commit 0f7f6af
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/cdk-assets/lib/private/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Logger = (x: string) => void;
export async function zipDirectory(directory: string, outputFile: string, logger: Logger): Promise<void> {
// We write to a temporary file and rename at the last moment. This is so that if we are
// interrupted during this process, we don't leave a half-finished file in the target location.
const temporaryOutputFile = `${outputFile}._tmp`;
const temporaryOutputFile = `${outputFile}.${randomString()}._tmp`;
await writeZipFile(directory, temporaryOutputFile);
await moveIntoPlace(temporaryOutputFile, outputFile, logger);
}
Expand Down Expand Up @@ -96,4 +96,8 @@ async function pathExists(x: string) {
}
throw e;
}
}

export function randomString() {
return Math.random().toString(36).replace(/[^a-z0-9]+/g, '');
}

0 comments on commit 0f7f6af

Please sign in to comment.