File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 11
11
import pathlib
12
12
import shutil
13
13
import subprocess
14
+ import platform
15
+ import time
14
16
from python .runfiles import runfiles
15
17
16
18
runfiles = runfiles .Create ()
41
43
assert destdir .is_absolute (), "Provide `--build-file` to resolve destination directory"
42
44
script = runfiles .Rlocation (opts .pkg_install_script )
43
45
46
+ _WIN_FILE_IN_USE_ERROR_CODE = 32
47
+
44
48
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 )
46
65
47
66
destdir .mkdir (parents = True , exist_ok = True )
48
67
subprocess .run ([script , "--destdir" , destdir ], check = True )
You can’t perform that action at this time.
0 commit comments