blob: 2559203ff09ab754bbc90a81357c8830a58b8e89 [file] [log] [blame]
Imre Kisa465cf42024-04-11 14:30:31 +02001From 388b2d044d3cdab89b7e5e6de94436ca78e1a13b Mon Sep 17 00:00:00 2001
2From: Imre Kis <imre.kis@arm.com>
3Date: Thu, 11 Apr 2024 14:20:16 +0200
4Subject: [PATCH] Fix race condition in directory creation
5
6nanopb_generator.py tests if the output directory exists and creates it
7if not. Because of these two steps are not atomic, there's a chance of
8multiple processes trying to create the directory. One process will
9succeed but the other will fail because the directory already exists.
10Allow existing directory on makedirs call to prevent this issue.
11
12Signed-off-by: Imre Kis <imre.kis@arm.com>
13---
14 generator/nanopb_generator.py | 2 +-
15 1 file changed, 1 insertion(+), 1 deletion(-)
16
17diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
18index c11f6fa..999aaf7 100755
19--- a/generator/nanopb_generator.py
20+++ b/generator/nanopb_generator.py
21@@ -2597,7 +2597,7 @@ def main_cli():
22 for path, data in to_write:
23 dirname = os.path.dirname(path)
24 if dirname and not os.path.exists(dirname):
25- os.makedirs(dirname)
26+ os.makedirs(dirname, exist_ok=True)
27
28 with open(path, 'w', encoding='utf-8') as f:
29 f.write(data)
30--
312.25.1
32