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

Discussion in 'Python' started by Scott Whitney, Feb 14, 2005.

  1. 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')?)
     
    Scott Whitney, Feb 14, 2005
    #1
    1. Advertising

  2. 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>
     
    Fredrik Lundh, Feb 14, 2005
    #2
    1. Advertising

  3. Scott  Whitney

    Jeff Epler Guest

    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+R5m4q4kIZfxUq3rFoqMgCgpOQq
    Z+qkuXf4jsxiPGmJPMm3EOw=
    =uBq3
    -----END PGP SIGNATURE-----
     
    Jeff Epler, Feb 15, 2005
    #3
  4. Scott  Whitney

    JustScott Guest

    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 <> 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
    >
    >
    >
     
    JustScott, Feb 16, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. viza

    &errno, sizeof errno

    viza, Sep 12, 2008, in forum: C Programming
    Replies:
    20
    Views:
    1,002
    Tim Rentsch
    Sep 14, 2008
  2. Glenn Linderman

    errno 22 instead of errno 2

    Glenn Linderman, Jan 28, 2009, in forum: Python
    Replies:
    0
    Views:
    367
    Glenn Linderman
    Jan 28, 2009
  3. Richard
    Replies:
    2
    Views:
    1,799
    Richard
    Mar 11, 2010
  4. snacktime
    Replies:
    1
    Views:
    127
    snacktime
    Aug 2, 2006
  5. Greg

    Cross-device link error

    Greg, Apr 20, 2007, in forum: Ruby
    Replies:
    2
    Views:
    221
    Nobuyoshi Nakada
    Apr 20, 2007
Loading...

Share This Page