Commit 9a8cb0aa authored by kbu's avatar kbu

fix #295: temporary egg files are created as read only and can't be deleted with shutil on Windows

parent 722dfc1b
......@@ -35,6 +35,7 @@ import subprocess
import sys
import tempfile
import zc.buildout
import zc.buildout.rmtree
import warnings
try:
......@@ -453,7 +454,7 @@ class Installer:
return result
finally:
shutil.rmtree(tmp)
zc.buildout.rmtree.rmtree(tmp)
def _obtain(self, requirement, source=None):
# initialize out index for this project:
......@@ -574,7 +575,7 @@ class Installer:
finally:
if tmp != self._download_cache:
shutil.rmtree(tmp)
zc.buildout.rmtree.rmtree(tmp)
self._env_rescan_dest()
dist = self._env.best_match(requirement, ws)
......@@ -804,11 +805,11 @@ class Installer:
return [dist.location for dist in dists]
finally:
shutil.rmtree(build_tmp)
zc.buildout.rmtree.rmtree(build_tmp)
finally:
if tmp != self._download_cache:
shutil.rmtree(tmp)
zc.buildout.rmtree.rmtree(tmp)
def _fix_file_links(self, links):
for link in links:
......@@ -945,7 +946,7 @@ def build(spec, dest, build_ext,
def _rm(*paths):
for path in paths:
if os.path.isdir(path):
shutil.rmtree(path)
zc.buildout.rmtree.rmtree(path)
elif os.path.exists(path):
os.remove(path)
......@@ -1051,7 +1052,7 @@ def develop(setup, dest,
)).encode())
tmp3 = tempfile.mkdtemp('build', dir=dest)
undo.append(lambda : shutil.rmtree(tmp3))
undo.append(lambda : zc.buildout.rmtree.rmtree(tmp3))
args = [executable, tsetup, '-q', 'develop', '-mN', '-d', tmp3]
......@@ -1738,5 +1739,5 @@ def _move_to_eggs_dir_and_compile(dist, dest):
assert newdist is not None # newloc above is missing our dist?!
finally:
# Remember that temporary directories must be removed
shutil.rmtree(tmp_dest)
zc.buildout.rmtree.rmtree(tmp_dest)
return newdist
......@@ -16,13 +16,15 @@
import shutil
import os
import doctest
import time
def rmtree (path):
"""
A variant of shutil.rmtree which tries hard to be successful
A variant of shutil.rmtree which tries hard to be successful.
On windows shutil.rmtree aborts when it tries to delete a
read only file.
This tries to chmod the file to writeable and retries before giving up.
read only file or a file which is still handled by another
process (e.g. antivirus scanner). This tries to chmod the
file to writeable and retries 10 times before giving up.
>>> from tempfile import mkdtemp
......@@ -55,7 +57,18 @@ def rmtree (path):
"""
def retry_writeable (func, path, exc):
os.chmod (path, 384) # 0600
tries = 10
while tries:
try:
func (path)
break
except OSError:
tries -= 1
time.sleep(0.1)
else:
# tried 10 times without success, thus
# finally rethrow the last exception
raise
shutil.rmtree (path, onerror = retry_writeable)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment