Commit f564ad78 authored by Reinout van Rees's avatar Reinout van Rees Committed by GitHub

Merge pull request #454 from k-bu/master

fix #295: temporary egg files are created as read only and can't be deleted with shutil on Windows.
parents 722dfc1b b96efa4f
...@@ -35,6 +35,7 @@ import subprocess ...@@ -35,6 +35,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import zc.buildout import zc.buildout
import zc.buildout.rmtree
import warnings import warnings
try: try:
...@@ -453,7 +454,7 @@ class Installer: ...@@ -453,7 +454,7 @@ class Installer:
return result return result
finally: finally:
shutil.rmtree(tmp) zc.buildout.rmtree.rmtree(tmp)
def _obtain(self, requirement, source=None): def _obtain(self, requirement, source=None):
# initialize out index for this project: # initialize out index for this project:
...@@ -574,7 +575,7 @@ class Installer: ...@@ -574,7 +575,7 @@ class Installer:
finally: finally:
if tmp != self._download_cache: if tmp != self._download_cache:
shutil.rmtree(tmp) zc.buildout.rmtree.rmtree(tmp)
self._env_rescan_dest() self._env_rescan_dest()
dist = self._env.best_match(requirement, ws) dist = self._env.best_match(requirement, ws)
...@@ -804,11 +805,11 @@ class Installer: ...@@ -804,11 +805,11 @@ class Installer:
return [dist.location for dist in dists] return [dist.location for dist in dists]
finally: finally:
shutil.rmtree(build_tmp) zc.buildout.rmtree.rmtree(build_tmp)
finally: finally:
if tmp != self._download_cache: if tmp != self._download_cache:
shutil.rmtree(tmp) zc.buildout.rmtree.rmtree(tmp)
def _fix_file_links(self, links): def _fix_file_links(self, links):
for link in links: for link in links:
...@@ -945,7 +946,7 @@ def build(spec, dest, build_ext, ...@@ -945,7 +946,7 @@ def build(spec, dest, build_ext,
def _rm(*paths): def _rm(*paths):
for path in paths: for path in paths:
if os.path.isdir(path): if os.path.isdir(path):
shutil.rmtree(path) zc.buildout.rmtree.rmtree(path)
elif os.path.exists(path): elif os.path.exists(path):
os.remove(path) os.remove(path)
...@@ -1051,7 +1052,7 @@ def develop(setup, dest, ...@@ -1051,7 +1052,7 @@ def develop(setup, dest,
)).encode()) )).encode())
tmp3 = tempfile.mkdtemp('build', dir=dest) 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] args = [executable, tsetup, '-q', 'develop', '-mN', '-d', tmp3]
...@@ -1738,5 +1739,5 @@ def _move_to_eggs_dir_and_compile(dist, dest): ...@@ -1738,5 +1739,5 @@ def _move_to_eggs_dir_and_compile(dist, dest):
assert newdist is not None # newloc above is missing our dist?! assert newdist is not None # newloc above is missing our dist?!
finally: finally:
# Remember that temporary directories must be removed # Remember that temporary directories must be removed
shutil.rmtree(tmp_dest) zc.buildout.rmtree.rmtree(tmp_dest)
return newdist return newdist
...@@ -16,13 +16,15 @@ ...@@ -16,13 +16,15 @@
import shutil import shutil
import os import os
import doctest import doctest
import time
def rmtree (path): 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 On windows shutil.rmtree aborts when it tries to delete a
read only file. read only file or a file which is still handled by another
This tries to chmod the file to writeable and retries before giving up. process (e.g. antivirus scanner). This tries to chmod the
file to writeable and retries 10 times before giving up.
>>> from tempfile import mkdtemp >>> from tempfile import mkdtemp
...@@ -55,7 +57,16 @@ def rmtree (path): ...@@ -55,7 +57,16 @@ def rmtree (path):
""" """
def retry_writeable (func, path, exc): def retry_writeable (func, path, exc):
os.chmod (path, 384) # 0600 os.chmod (path, 384) # 0600
func (path) for i in range(10):
try:
func (path)
break
except OSError:
time.sleep(0.1)
else:
# tried 10 times without success, thus
# finally rethrow the last exception
raise
shutil.rmtree (path, onerror = retry_writeable) 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