473,750 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

symlink overwrite


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!

--
ma***@reimeika. ca
Gunnm: Broken Angel http://amv.reimeika.ca
http://reimeika.ca/ http://photo.reimeika.ca
Jul 18 '05 #1
1 4493
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)

iD8DBQFBCDMcJd0 1MZaTXX0RAry+AJ 9eu66f4Xjw6L3Hp q7SRMKqQdOzZgCf WJTv
5AczIY+fOkynz4Q jRSjUQD4=
=HvwM
-----END PGP SIGNATURE-----

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5954
by: Patrick Lioi | last post by:
I've developed a simple content management system in PHP, and I'd like to be able to put the code for it in a single place, and have several sites on one server seamlessly share the code. I want to put the app itself in /DOCROOT/MyCMS/. I want to put a site that uses it in, say, /DOCROOT/site1, /DOCROOT/site2, etc. I want to place a symlink to /DOCROOT/MyCMS/ inside each site
0
1861
by: A. Murat Eren | last post by:
Hi, I have a problem about zipfile. I'm trying to add files from local file system into a zip file via zipfile module of python.. I have a function in my class which recursively adds files or dirs into zip: -------8<-------------------8<--------------------8<------------------8<----- def add_file(self, fileName):
0
1391
by: MD Raziuddin Haqqani | last post by:
------=_NextPart_000_00FC_01C35142.4E7FDE00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Is there any way to create a symlink of table in two different = databases which belongs to the same user. It will be great help if I get the solution for above mention task. =20
0
1446
by: lynn | last post by:
Hello, I tried to install on my mac osx 10.3.3 my mysql 4.0.13 databases on an other partition than its application; I know it is possible because I managed to do it previously with jaguar. So, as I did before, I copied complete var of mysql into the other partition. I eliminated the var in mysql directory and I made a "var" symlink between the mysql directory and the var new location ; after I verified the group, user name and...
2
27763
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want to overwrite", "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
2
1690
by: wheresjim | last post by:
I have a project in which I only need read access to a Microsoft Access database (.mdb file) via JDBC and unfortunately, the file is frequently locked by another application when I need access to it. I figured that I could bypass the lock file by creating a symlink (my os is Fedora Core 3 Linux) and just putting the url to the Symlink into the connection. Obviously I am having problems with this approach. Has anyone else done
1
2272
by: | last post by:
I'm developing a website (PHP/Apache), and I need to be able to use a 'symlink' inside a URL where the symlink is a folder not a file. I have been able to use symlinks that point directly to a file. Now I need to be able to have the symlink point to a folder (which is a parent to other content). I have used PHP code to generate a SYMLINK to a folder, and I have successfully tested the symlink through PUTTY. What I can't seem to do is...
1
2551
by: ravimane27 | last post by:
can someone tell me about symlink or softlink or symbolic link in windows? i want to access network drives using softlink, can i do this? how? thanks in advance.
2
7347
by: Nikolaus Rath | last post by:
Hello, symlink(...) symlink(src, dst) Create a symbolic link pointing to src named dst. Is there any reason why this is so deliberately confusing? Why is the
0
9000
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.