symlink overwrite

Discussion in 'Python' started by marco, Jul 28, 2004.

  1. marco

    marco Guest

    marco, Jul 28, 2004
    #1
    1. Advertising

  2. marco

    Jeff Epler Guest

    On Wed, Jul 28, 2004 at 06:51:15PM -0400, marco wrote:
    >
    > Hi all,
    >
    > I know about os.symlink(src, dst), but is there
    > a way to overwrite an existing symlink e.g. "ln -sf"?
    > Short of checking and, if necessary, having to delete
    > the existing link by hand...


    That's what gnu ln does for "ln -sf", though for good measure it stat()s
    three times!

    $ strace -e stat64,symlink,unlink ln -sf a b
    stat64("b", 0xfeee1290) = -1 ENOENT (No such file or directory)
    symlink("a", "b") = 0

    $ strace -e stat64,symlink,unlink ln -sf a b
    stat64("b", 0xfeef69e0) = -1 ENOENT (No such file or directory)
    stat64("b", 0xfeef68d0) = -1 ENOENT (No such file or directory)
    stat64("a", 0xfeef69d0) = -1 ENOENT (No such file or directory)
    unlink("b") = 0
    symlink("a", "b") = 0

    A single os.lstat() should do nicely in your case, or a catch around the
    unlink.

    Jeff

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

    iD8DBQFBCDMcJd01MZaTXX0RAry+AJ9eu66f4Xjw6L3Hpq7SRMKqQdOzZgCfWJTv
    5AczIY+fOkynz4QjRSjUQD4=
    =HvwM
    -----END PGP SIGNATURE-----
     
    Jeff Epler, Jul 29, 2004
    #2
    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. onetitfemme
    Replies:
    6
    Views:
    526
    onetitfemme
    Nov 2, 2005
  2. Replies:
    4
    Views:
    800
    Daniel Dittmar
    Dec 16, 2004
  3. A. Murat Eren

    zipfile + symlink..

    A. Murat Eren, Jun 23, 2005, in forum: Python
    Replies:
    0
    Views:
    390
    A. Murat Eren
    Jun 23, 2005
  4. A. Murat Eren

    Re: zipfile + symlink [Solved]..

    A. Murat Eren, Jun 24, 2005, in forum: Python
    Replies:
    0
    Views:
    1,741
    A. Murat Eren
    Jun 24, 2005
  5. Giampaolo Rodola'

    Check if a symlink is broken or circular

    Giampaolo Rodola', Nov 30, 2007, in forum: Python
    Replies:
    3
    Views:
    345
Loading...

Share This Page