classification
Title: Use shutil.move instead of os.rename in packaging
Type: Stage: resolved
Components: Distutils2 Versions: Python 3.3, 3rd party
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: alexis Nosy List: alexis, eric.araujo, nvetoshkin, tarek
Priority: normal Keywords:

Created on 2012-05-18 08:50 by nvetoshkin, last changed 2014-03-13 08:34 by eric.araujo. This issue is now closed.

Messages (7)
msg161042 - (view) Author: Vetoshkin Nikita (nvetoshkin) Date: 2012-05-18 08:50
When I attempt to remove package with pysetup remove 'package-name' on Fedora 17 - it fails with:
'my-package' cannot be removed
Error: [Errno 18] Invalid cross-device link

strace'ing showed that there was an attempt to call rename from package dir into /tmp which is tmpfs.

Proposed fix is trivial - use shutil.move instead of barebone os.rename.
msg161052 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-05-18 14:41
How did you install my-package?
msg161053 - (view) Author: Vetoshkin Nikita (nvetoshkin) Date: 2012-05-18 14:45
pysetup install.
strace of removal looks like this:
stat("/home/nekto0n/workspace/pillar/penv/lib/python2.7/site-packages/ygroup/__init__.py", {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
rename("/home/nekto0n/workspace/pillar/penv/lib/python2.7/site-packages/ygroup/__init__.py", "/tmp/ygroup-client-uninstalljkoIAl/__init__.py") = -1 EXDEV (Invalid cross-device link)
msg162572 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-06-10 01:31
OK.  Can you paste the full traceback for the error?
msg162751 - (view) Author: Vetoshkin Nikita (nvetoshkin) Date: 2012-06-14 04:50
Sorry, no traceback by default, had to augment with "raise" :) Now output looks like this:

nekto0n@ya-darkstar /var/tmp/mypackage $ pysetup remove pygraphviz
u'workflow': u'1.01' is not a valid version (field 'Version')
u'zc-zookeeper-static': u'3.4.3-3' is not a valid version (field 'Version')
u'virtkey': u'0.01' is not a valid version (field 'Version')
u'SSSDConfig': u'1' is not a valid version (field 'Version')
[Errno 18] Invalid cross-device link
Traceback (most recent call last):
  File "/home/nekto0n/.local/lib/python2.7/site-packages/distutils2/run.py", line 651, in main
    return dispatcher()
  File "/home/nekto0n/.local/lib/python2.7/site-packages/distutils2/run.py", line 639, in __call__
    return func(self, self.args)
  File "/home/nekto0n/.local/lib/python2.7/site-packages/distutils2/run.py", line 91, in wrapper
    return f(*args, **kwargs)
  File "/home/nekto0n/.local/lib/python2.7/site-packages/distutils2/run.py", line 239, in _remove
    remove(dist, auto_confirm=auto_confirm)
  File "/home/nekto0n/.local/lib/python2.7/site-packages/distutils2/install.py", line 413, in remove
    error = _move_file(file_, tmpfile)
  File "/home/nekto0n/.local/lib/python2.7/site-packages/distutils2/install.py", line 399, in _move_file
    os.rename(source, target)
OSError: [Errno 18] Invalid cross-device link

According to strace arguments to rename where:
rename("/home/nekto0n/.local/lib/python2.7/site-packages/pygraphviz-1.1-py2.7.egg-info/PKG-INFO", "/tmp/pygraphviz-uninstallIiAQ1I/PKG-INFO") = -1 EXDEV (Invalid cross-device link)
msg162753 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-06-14 05:17
Thanks!  As your message shows the problem is in the install module, I propose to close this bug as a duplicate of Alexis’ bug about improving d2.install.  The new FileMover class should use shutil.move, and we’ll make sure to test install+remove as you did to see if the bug is gone.
msg162755 - (view) Author: Vetoshkin Nikita (nvetoshkin) Date: 2012-06-14 05:19
glad to help
History
Date User Action Args
2014-03-13 08:34:46eric.araujosetstatus: open -> closed
resolution: out of date
stage: needs patch -> resolved
2012-06-14 05:19:43nvetoshkinsetmessages: + msg162755
2012-06-14 05:17:11eric.araujosetassignee: eric.araujo -> alexis
messages: + msg162753
2012-06-14 04:50:17nvetoshkinsetmessages: + msg162751
2012-06-10 01:31:51eric.araujosettitle: os.rename should not be used -> Use shutil.move instead of os.rename in packaging
messages: + msg162572
stage: needs patch
2012-05-18 14:45:06nvetoshkinsetmessages: + msg161053
2012-05-18 14:41:54eric.araujosetmessages: + msg161052
versions: + 3rd party, Python 3.3, - Python 2.7
2012-05-18 08:50:31nvetoshkincreate