Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [Errno 18] Invalid cross-device link using os.rename

Reply
Thread Tools

[Errno 18] Invalid cross-device link using os.rename

 
 
Scott Whitney
Guest
Posts: n/a
 
      02-14-2005
oldName=/backup/backups/data/WWW_httpd.conf_backups/20050204.httpd.conf

newName=/backup_old/data/WWW_httpd.conf_backups/20050204.httpd.conf

os.rename(oldName,newName) gives:

OSError: [Errno 18] Invalid cross-device link

mv from the shell works fine.

This is Python 2.2.3 from RedHat 9.0.

Any suggestions (other than os.system('mv %s %s')?)

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      02-14-2005
Scott Whitney wrote:

> os.rename(oldName,newName) gives:
>
> OSError: [Errno 18] Invalid cross-device link
>
> mv from the shell works fine.
>
> This is Python 2.2.3 from RedHat 9.0.
>
> Any suggestions (other than os.system('mv %s %s')?)


catch exception and copy if error == errno.EXDEV.

(this is what "mv" does, of course)

or use shutil.move:

>>> import shutil
>>> help(shutil.move)

Help on function move in module shutil:

move(src, dst)
Recursively move a file or directory to another location.

If the destination is on our current filesystem, then simply use
rename. Otherwise, copy src to the dst and then remove src.
A lot more could be done here... A look at a mv.c shows a lot of
the issues this implementation glosses over.

</F>



 
Reply With Quote
 
 
 
 
Jeff Epler
Guest
Posts: n/a
 
      02-15-2005
mv is a surprisingly complex program, while os.rename is a wrapper
around rename(2) which is probably documented on your system to return
EXDEV under these circumstanes.

os.xxx is generally a fairly thin wrapper around what your OS provides,
and inherits all the "gotchas". For some activities, os.shutil provides
something that is between os.xxx and os.system("xxx") in complexity and
capability.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCEULWJd01MZaTXX0RAuavAKCX1bQui+R5m4q4kIZfxU q3rFoqMgCgpOQq
Z+qkuXf4jsxiPGmJPMm3EOw=
=uBq3
-----END PGP SIGNATURE-----

 
Reply With Quote
 
JustScott
Guest
Posts: n/a
 
      02-16-2005
Thanks, Jeff. I appreciate the input. I just stuck with os.system('mv
%s %s'). Seems to work fine.


On Mon, 14 Feb 2005 18:31:18 -0600, Jeff Epler <(E-Mail Removed)> wrote:
> mv is a surprisingly complex program, while os.rename is a wrapper
> around rename(2) which is probably documented on your system to return
> EXDEV under these circumstanes.
>
> os.xxx is generally a fairly thin wrapper around what your OS provides,
> and inherits all the "gotchas". For some activities, os.shutil provides
> something that is between os.xxx and os.system("xxx") in complexity and
> capability.
>
> Jeff
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do fix: "Wrong number of arguments" / "invalid propert assignment"/ "Invalid argument" Java Guy Java 1 10-15-2006 08:31 PM
Invalid URI: There is an invalid sequence in the string. Error!! Patrick.O.Ige ASP .Net 1 07-02-2006 11:21 AM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
invalid@invalid.org Hank Sniadoch Computer Information 1 08-20-2004 11:24 AM



Advertisments