From a8bf40c7bf9dd47ede55ce9b2c53f2ddb48b6446 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Wed, 8 Feb 2023 14:31:20 -0500 Subject: [PATCH] Only sleep between rmtree and mkdir on Windows machines This makes amalgamate builds slightly faster on non-Windows machines. --- amalgamate.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/amalgamate.py b/amalgamate.py index 57604c97..e2aa8eb6 100644 --- a/amalgamate.py +++ b/amalgamate.py @@ -19,7 +19,12 @@ import time if os.path.exists("amalgamated"): shutil.rmtree("amalgamated") - time.sleep(1) + if os.name == "nt": + # On Windows, making a directory too soon after shutil.rmtree can fail + # with PermissionError. Sleep for 1 second as a simple hedge against + # this. + # See https://stackoverflow.com/a/60181105/569183 + time.sleep(1) os.mkdir("amalgamated") def remove_copied_include(text):