Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > symlink overwrite

Reply
Thread Tools

symlink overwrite

 
 
marco
Guest
Posts: n/a
 
      07-28-2004

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...

Thanks!

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
Gunnm: Broken Angel http://amv.reimeika.ca
http://reimeika.ca/ http://photo.reimeika.ca
 
Reply With Quote
 
 
 
 
Jeff Epler
Guest
Posts: n/a
 
      07-28-2004
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+AJ9eu66f4Xjw6L3Hpq7SRM KqQdOzZgCfWJTv
5AczIY+fOkynz4QjRSjUQD4=
=HvwM
-----END PGP SIGNATURE-----

 
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
Check if a symlink is broken or circular Giampaolo Rodola' Python 3 12-01-2007 06:28 PM
symlink errors while installing java . . . onetitfemme Java 6 11-02-2005 08:59 PM
Re: zipfile + symlink [Solved].. A. Murat Eren Python 0 06-24-2005 09:29 AM
zipfile + symlink.. A. Murat Eren Python 0 06-23-2005 08:43 PM
cygwin python.exe symlink breaks when called from .bat file gry@ll.mit.edu Python 4 12-16-2004 01:11 PM



Advertisments