[ python-Bugs-212317 ] os.rename transparent handling of cross-filesystem issues

SourceForge.net noreply at sourceforge.net
Mon Jan 19 08:33:13 EST 2004


Bugs item #212317, was opened at 2000-08-19 12:09
Message generated for change (Comment added) made by jepler
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=212317&group_id=5470

Category: Python Library
Group: Feature Request
Status: Closed
Resolution: Later
Priority: 3
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: os.rename transparent handling of cross-filesystem issues

Initial Comment:
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.




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

Comment By: Jeff Epler (jepler)
Date: 2004-01-19 07:33

Message:
Logged In: YES 
user_id=2772

I saw this item in PEP42 and I'd also like to be on the
record against making os.rename() do fancy stuff.  If you
want shutil.move, you know where to find it.  As "nobody"
mentions, we unix people know exactly what rename(2) does,
and we want os.rename() to be a thin wrapper over it.

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

Comment By: Thiébaut Champenier (tibi)
Date: 2003-12-09 06:34

Message:
Logged In: YES 
user_id=25413

Since Python 2.3 the shutil module has a move function that 
implements this functionality.

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

Comment By: Nobody/Anonymous (nobody)
Date: 2002-03-08 11:03

Message:
Logged In: NO 

also unix weenies expect rename() to be atomic. making
it non-atomic can break lots of code that is carefully
crafted to survive nfs, or do locking with rename(), etc.


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

Comment By: Guido van Rossum (gvanrossum)
Date: 2000-10-30 12:43

Message:
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).


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

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2000-09-15 15:01

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

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

Comment By: Jeremy Hylton (jhylton)
Date: 2000-09-07 17:05

Message:
Please do triage on this bug.

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

Comment By: Jeremy Hylton (jhylton)
Date: 2000-08-25 09:44

Message:
revisit this after 2.0


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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=212317&group_id=5470



More information about the Python-bugs-list mailing list