Skip to content

Commit c97d488

Browse files
authored
Python: fix calls to os.makedirs to avoid existence check races (microsoft#6060)
In parallel builds of DXC, hctgen.py in particuilar would sometimes throw an exception from os.makedirs because the directory would already exist. The conditional check for file existence introduces a race when running the script in parallel. Fix this, and all other cases where such conditional checks were done, by using the `exist_ok = True` argument.
1 parent 7b222ff commit c97d488

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

utils/hct/hctgen.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def writeCodeTag(args):
6767

6868
def openOutput(args):
6969
outputDir = os.path.dirname(os.path.realpath(args.output))
70-
if not os.path.exists(outputDir):
71-
os.makedirs(outputDir)
70+
os.makedirs(outputDir, exist_ok=True)
7271
return open(args.output, "w", newline=getNewline(args))
7372

7473

utils/hct/hctgettaef.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
src_dir = os.environ["HLSL_SRC_DIR"]
1111
taef_dir = os.path.join(src_dir, "external", "taef")
1212

13-
if not os.path.isdir(taef_dir):
14-
os.makedirs(taef_dir)
13+
os.makedirs(taef_dir, exist_ok=True)
1514

1615
try:
1716
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

0 commit comments

Comments
 (0)