Skip to content

Commit 0fa2eba

Browse files
authored
Handle Access Denied error when cleaning up build directory on Windows (#960)
* Handle Access Denied error when cleaning up build directory on Windows
1 parent 2037576 commit 0fa2eba

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/gha/build_testapps.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import os
8080
import platform
8181
import shutil
82+
import stat
8283
import subprocess
8384
import sys
8485
import tempfile
@@ -697,11 +698,17 @@ def _run(args, timeout=_DEFAULT_RUN_TIMEOUT_SECONDS, capture_output=False, text=
697698
check=check)
698699

699700

701+
def _handle_readonly_file(func, path, excinfo):
702+
"""Function passed into shutil.rmtree to handle Access Denied error"""
703+
os.chmod(path, stat.S_IWRITE)
704+
func(path) # will re-throw if a different error occurrs
705+
706+
700707
def _rm_dir_safe(directory_path):
701708
"""Removes directory at given path. No error if dir doesn't exist."""
702709
logging.info("Deleting %s...", directory_path)
703710
try:
704-
shutil.rmtree(directory_path)
711+
shutil.rmtree(directory_path, onerror=_handle_readonly_file)
705712
except OSError as e:
706713
# There are two known cases where this can happen:
707714
# The directory doesn't exist (FileNotFoundError)

0 commit comments

Comments
 (0)