From 2847f78ab200c3f8c7be9c9c49d2b64f53f26d44 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Thu, 20 Feb 2020 09:15:35 +0100 Subject: [PATCH] appveyor: add error handler to fix shutil.rmtree on Windows --- appveyor-test.py | 2 +- appveyor/do.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/appveyor-test.py b/appveyor-test.py index 2180eef..7b3f3d8 100644 --- a/appveyor-test.py +++ b/appveyor-test.py @@ -165,7 +165,7 @@ class TestAddDependency(unittest.TestCase): def setUp(self): os.environ['SETUP_PATH'] = '.:appveyor' if os.path.exists(self.location): - shutil.rmtree(self.location) + shutil.rmtree(self.location, onerror=do.remove_readonly) do.clear_lists() os.chdir(builddir) do.source_set('defaults') diff --git a/appveyor/do.py b/appveyor/do.py index d0a9064..3b0ef55 100644 --- a/appveyor/do.py +++ b/appveyor/do.py @@ -4,7 +4,8 @@ from __future__ import print_function -import sys, os, shutil, fileinput +import sys, os, stat, shutil +import fileinput import logging import subprocess as sp import distutils.util @@ -37,6 +38,11 @@ def clear_lists(): del modules_to_compile[:] setup.clear() +# Error-handler to make shutil.rmtree delete read-only files on Windows +def remove_readonly(func, path, excinfo): + os.chmod(path, stat.S_IWRITE) + func(path) + # source_set(setup) # # Source a settings file (extension .set) found in the setup_dirs path @@ -190,7 +196,7 @@ def add_dependency(dep, tag): logger.debug('Found checked_out commit %s, git head is %s', checked_out, head) if head != checked_out: logger.debug('Dependency %s out of date - removing', dep) - shutil.rmtree(place) + shutil.rmtree(place, onerror=remove_readonly) else: print('Found {0} of dependency {1} up-to-date in {2}'.format(tag, dep, place))