From 20a6ca0041379a0aebeca7fdff753416a4ab1ffa Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 19 Dec 2022 11:14:54 +0000 Subject: [PATCH] generator_lib.py: Fix exception when racing for dir creation. The generator_lib.py processing of file renders would check that the output directory doesn't exist and if needed, would create it. However by default makedirs errors if the path already exists. This caused issues when multiple generator_lib.py generators with the same output dir would run in parallel in builds, because there can be a race where: - GeneratorA: Check os.path.exists -> returns False - GeneratorB: Check os.path.exists -> returns False - GeneratorB: os.makedirs -> Ok - GeneratorA: os.makedirs -> Exception, fails the build. Instead use os.makedirs(exist_ok=True) inconditionally to remove this racy behavior. Bug: None Change-Id: I5cb401a1df11a3640faeea94c15cb54236edc05a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114521 Commit-Queue: Corentin Wallez Reviewed-by: Ben Clayton Kokoro: Kokoro --- generator/generator_lib.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/generator/generator_lib.py b/generator/generator_lib.py index dbff07e27b..c198722f09 100644 --- a/generator/generator_lib.py +++ b/generator/generator_lib.py @@ -335,8 +335,7 @@ def run_generator(generator): output_path = os.path.join(args.output_dir, output.name) directory = os.path.dirname(output_path) - if not os.path.exists(directory): - os.makedirs(directory) + os.makedirs(directory, exist_ok=True) with open(output_path, 'w') as outfile: outfile.write(output.content)