[Python-bugs-list] [Bug #112317] os.rename transparent handling of cross-filesystem issues

noreply@sourceforge.net noreply@sourceforge.net
Mon, 30 Oct 2000 10:43:45 -0800


Bug #112317, was updated on 2000-Aug-19 10:09
Here is a current snapshot of the bug.

Project: Python
Category: Library
Status: Closed
Resolution: Later
Bug Group: Feature Request
Priority: 3
Summary: os.rename transparent handling of cross-filesystem issues

Details: On some systems (specifically, Linux), the rename system call will throw
an EXDEV error if rename is used across filesystems.  It would be convenient for the user if os.rename were extended to handle this transparently (like most mv commands do).

The benefits of this. . .getting rid of code like the following:

try:
    os.rename('ff','/tmp/ff')
except:
    open('/tmp/ff','w').write(open('ff','r').read())
    os.unlink('ff')

Actually, the real benefit is that code (written by morons like myself) using os.rename will continue to work even after the administrator moves the target directory to another filesystem.

I took a quick look at posixmodule.c.  A quick hack changes posix_2str's
signature to the following:

PyObject *args
char *format
int (*func)(const char*, const char *)
int (*special_handler)(const char *, const char *)

and the inner function to:

if (res != 0)
    if ((! special_handler) || (*special_handler)(path1,path2))
         return posix_error()

Of course, then a smart copy routine (includes an unlink step).  The most unclear thing at this point is what to do with the errno.  Would a failure in
the errorhandler report the original errno or its own errno???

Personally, a more general solution would allow the user (python-level) to optionally pass in *their own* error handling function/method.




Follow-Ups:

Date: 2000-Aug-25 07:44
By: jhylton

Comment:
revisit this after 2.0

-------------------------------------------------------

Date: 2000-Sep-07 15:05
By: jhylton

Comment:
Please do triage on this bug.
-------------------------------------------------------

Date: 2000-Sep-15 13:01
By: fdrake

Comment:
Moved to PEP 42 as a feature request for a post-2.0 version of Python.
-------------------------------------------------------

Date: 2000-Oct-30 10:43
By: gvanrossum

Comment:
Copying files (and directories) properly is a very platform specific task -- there are lots of pitfalls that the copying code has to watch out for, e.g. copying files with "holes", properly copying all metadata, copying special files... I think that the os.rename() call is not the proper place to implement all this. But it's a useful feature nevertheless, and could perhaps be accommodated by a higher level function in the shutil module (which has the basic copying primitives).

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=112317&group_id=5470