Fix git clone related issues on Windows

This commit is contained in:
Paul O'Leary McCann 2023-02-20 16:09:34 +09:00
parent 95bed8a4a0
commit dc42ab48d2

View File

@ -1050,8 +1050,15 @@ def make_tempdir() -> Generator[Path, None, None]:
""" """
d = Path(tempfile.mkdtemp()) d = Path(tempfile.mkdtemp())
yield d yield d
# On Windows, git clones use read-only files, which cause permission errors
# when being deleted. This forcibly fixes permissions.
def force_remove(rmfunc, path, ex):
os.chmod(path, stat.S_IWRITE)
rmfunc(path)
try: try:
shutil.rmtree(str(d)) shutil.rmtree(str(d), onerror=force_remove)
except PermissionError as e: except PermissionError as e:
warnings.warn(Warnings.W091.format(dir=d, msg=e)) warnings.warn(Warnings.W091.format(dir=d, msg=e))