Commit 9b6dcdbf authored by PJ Eby's avatar PJ Eby

D'oh! os.path.islink is available on all platforms. Also, ensure that we

do directory tree removals only if isdir() and not islink(), and use
unlink() in all other cases.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041230
parent b2382a4e
...@@ -104,9 +104,7 @@ class easy_install(Command): ...@@ -104,9 +104,7 @@ class easy_install(Command):
for filename in blockers: for filename in blockers:
log.info("Deleting %s", filename) log.info("Deleting %s", filename)
if not self.dry_run: if not self.dry_run:
if hasattr(os.path,'islink') and os.path.islink(filename): if os.path.isdir(filename) and not os.path.islink(filename):
os.unlink(filename)
elif os.path.isdir(filename):
shutil.rmtree(filename) shutil.rmtree(filename)
else: else:
os.unlink(filename) os.unlink(filename)
...@@ -121,6 +119,8 @@ class easy_install(Command): ...@@ -121,6 +119,8 @@ class easy_install(Command):
def finalize_options(self): def finalize_options(self):
# If a non-default installation directory was specified, default the # If a non-default installation directory was specified, default the
# script directory to match it. # script directory to match it.
...@@ -547,9 +547,9 @@ class easy_install(Command): ...@@ -547,9 +547,9 @@ class easy_install(Command):
dist = self.egg_distribution(egg_path) dist = self.egg_distribution(egg_path)
self.check_conflicts(dist) self.check_conflicts(dist)
if not samefile(egg_path, destination): if not samefile(egg_path, destination):
if os.path.isdir(destination): if os.path.isdir(destination) and not os.path.islink(destination):
dir_util.remove_tree(destination, dry_run=self.dry_run) dir_util.remove_tree(destination, dry_run=self.dry_run)
elif os.path.isfile(destination): elif os.path.exists(destination):
self.execute(os.unlink,(destination,),"Removing "+destination) self.execute(os.unlink,(destination,),"Removing "+destination)
if os.path.isdir(egg_path): if os.path.isdir(egg_path):
...@@ -841,24 +841,24 @@ See the setuptools documentation for the "develop" command for more info. ...@@ -841,24 +841,24 @@ See the setuptools documentation for the "develop" command for more info.
if dist.location not in self.shadow_path: if dist.location not in self.shadow_path:
self.shadow_path.append(dist.location) self.shadow_path.append(dist.location)
if not self.dry_run:
self.pth_file.save() self.pth_file.save()
if dist.key=='setuptools': if dist.key=='setuptools':
# Ensure that setuptools itself never becomes unavailable! # Ensure that setuptools itself never becomes unavailable!
# XXX should this check for latest version? # XXX should this check for latest version?
filename = os.path.join(self.install_dir,'setuptools.pth') filename = os.path.join(self.install_dir,'setuptools.pth')
unlink_if_symlink(filename) if os.path.islink(filename): unlink(filename)
f = open(filename, 'wt') f = open(filename, 'wt')
f.write(dist.location+'\n') f.write(dist.location+'\n')
f.close() f.close()
def unpack_progress(self, src, dst): def unpack_progress(self, src, dst):
# Progress filter for unpacking # Progress filter for unpacking
log.debug("Unpacking %s to %s", src, dst) log.debug("Unpacking %s to %s", src, dst)
return dst # only unpack-and-compile skips files for dry run return dst # only unpack-and-compile skips files for dry run
def unpack_and_compile(self, egg_path, destination): def unpack_and_compile(self, egg_path, destination):
to_compile = [] to_compile = []
...@@ -1017,9 +1017,9 @@ def extract_wininst_cfg(dist_filename): ...@@ -1017,9 +1017,9 @@ def extract_wininst_cfg(dist_filename):
f.close() f.close()
def unlink_if_symlink(filename):
if hasattr(os.path,'islink') and os.path.islink(filename):
os.unlink(filename)
...@@ -1100,11 +1100,11 @@ class PthDistributions(Environment): ...@@ -1100,11 +1100,11 @@ class PthDistributions(Environment):
if self.dirty: if self.dirty:
log.debug("Saving %s", self.filename) log.debug("Saving %s", self.filename)
data = '\n'.join(self.paths+['']) data = '\n'.join(self.paths+[''])
unlink_if_symlink(self.filename) if os.path.islink(self.filename):
os.unlink(self.filename)
f = open(self.filename,'wt'); f.write(data); f.close() f = open(self.filename,'wt'); f.write(data); f.close()
self.dirty = False self.dirty = False
def add(self,dist): def add(self,dist):
"""Add `dist` to the distribution map""" """Add `dist` to the distribution map"""
if dist.location not in self.paths: if dist.location not in self.paths:
......
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