Skip to content

Commit bb78536

Browse files
committed
Install script: Windows-compatible cleanup path.
Windows might need some retrying around deleting the target directory.
1 parent 0421cef commit bb78536

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

misc/bazel/internal/install.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import pathlib
1212
import shutil
1313
import subprocess
14+
import platform
15+
import time
1416
from python.runfiles import runfiles
1517

1618
runfiles = runfiles.Create()
@@ -42,8 +44,20 @@
4244
script = runfiles.Rlocation(opts.pkg_install_script)
4345

4446
if destdir.exists() and opts.cleanup:
45-
shutil.rmtree(destdir)
46-
47+
if platform.system() == 'Windows':
48+
# On Windows we might have virus scanner still looking at the path so
49+
# attempt removal a couple of times sleeping between each attempt.
50+
for attempt in [1, 2]:
51+
try:
52+
shutil.rmtree(destdir)
53+
break
54+
except OSError as e:
55+
if e.winerror == 32:
56+
time.sleep(attempt)
57+
else:
58+
raise
59+
else:
60+
shutil.rmtree(destdir)
4761
destdir.mkdir(parents=True, exist_ok=True)
4862
subprocess.run([script, "--destdir", destdir], check=True)
4963

0 commit comments

Comments
 (0)