[New-bugs-announce] [issue18201] distutils write into symlinks instead of replacing them

Michał Górny report at bugs.python.org
Thu Jun 13 07:18:55 CEST 2013


New submission from Michał Górny:

We're doing heavy wrapping of Python scripts on Gentoo in order to efficiently support having multiple versions of Python installed. For that reason, every Python script installed using the package manager is renamed, and a symlink to a common wrapper binary is installed in its place.

For example, setuptools install looks like:

  /usr/bin/easy_install -> python-exec
  /usr/bin/easy_install-python2.7
  /usr/bin/easy_install-python3.2

Using the wrappers like this allow us to actively support user preference of Python version and map it to supported ones. Symlinking a common binary makes this more maintainable since there's just one place where wrapper needs to be updated.

However, it seems that setup.py is failing hard in replacing symlinks. Whenever user upgrades any installed package, either externally or due to some tool like easy_install or pip, the relevant setup.py writes into /usr/bin/easy_install rather than properly replacing it with a new file.

The effect, as you may imagine, is the wrapper being replaced with a random Python script and system-wide breakage.

The proper thing to do would be to write into temporary file in the destination directory, then use os.rename() to atomically replace the destination with the temporary file.

Since distutils is no longer maintained, I would be equally happy with simply os.remove() before writing the scripts. The problem may affect distutils2 as well.

----------
assignee: eric.araujo
components: Distutils
messages: 191057
nosy: eric.araujo, mgorny, tarek
priority: normal
severity: normal
status: open
title: distutils write into symlinks instead of replacing them
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18201>
_______________________________________


More information about the New-bugs-announce mailing list