Skip to content

Commit f87e680

Browse files
authored
Merge pull request #16928 from github/criemen/install-remove
Install script: Windows-compatible cleanup path.
2 parents 496e76c + 16660ab commit f87e680

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

misc/bazel/internal/install.py

Lines changed: 20 additions & 1 deletion
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()
@@ -41,8 +43,25 @@
4143
assert destdir.is_absolute(), "Provide `--build-file` to resolve destination directory"
4244
script = runfiles.Rlocation(opts.pkg_install_script)
4345

46+
_WIN_FILE_IN_USE_ERROR_CODE = 32
47+
4448
if destdir.exists() and opts.cleanup:
45-
shutil.rmtree(destdir)
49+
if platform.system() == 'Windows':
50+
# On Windows we might have virus scanner still looking at the path so
51+
# attempt removal a couple of times sleeping between each attempt.
52+
for retry_delay in [1, 2, 2]:
53+
try:
54+
shutil.rmtree(destdir)
55+
break
56+
except OSError as e:
57+
if e.winerror == _WIN_FILE_IN_USE_ERROR_CODE:
58+
time.sleep(retry_delay)
59+
else:
60+
raise
61+
else:
62+
shutil.rmtree(destdir)
63+
else:
64+
shutil.rmtree(destdir)
4665

4766
destdir.mkdir(parents=True, exist_ok=True)
4867
subprocess.run([script, "--destdir", destdir], check=True)

0 commit comments

Comments
 (0)