help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make symbolic links?


From: Paul Smith
Subject: Re: how to make symbolic links?
Date: Thu, 08 Sep 2011 08:09:18 -0400

On Wed, 2011-09-07 at 23:17 -0700, Philip Guenther wrote:
> Symlinks, particularly relative symlinks, are weird in UNIX and a
> general wart on the design that has never been fully smoothed over,
> with special handling required by many systems calls and programs.

Although this has nothing to do with make, I don't agree with that.
They work the only way they could possibly work when it comes to
relative paths.  Nothing else would make sense.

Also, symlinks are not weird nor a wart on the design: they are fairly
excellent.  And the most excellent thing about symlinks is that
virtually NO system calls or programs require special handling for them.
They "just work", 99.99% of the time.

My $0.02.


For Mark: the rule for expanding symlinks is this: as you're walking a
directory path and you come across a symlink, then:

If the symlink target is a fully-qualified path (starts with "/"),
replace the entire current path with the contents of the symlink.

If the symlink target is NOT fully-qualified (doesn't start with "/"),
then remove the symlink element (the last filename in the path) and
replace it with the contents of the symlink.

So if you create a symlink:
        /my/special/foo  ->  /etc/passwd

then when the kernel wants to open "/my/special/foo" it walks the path
and when it gets to "foo" it sees it's a symlink, and the target is
fully-qualified, and it replaces the entire path with "/etc/passwd".

And if you create a symlink:
        /my/special/foo  ->  bar

then when the kernel gets to "foo" and sees it's a symlink, and the
target is NOT fully-qualified, it removes the link element ("foo") and
replaces it with the contents ("bar") giving "/my/special/bar".

And if you create a symlink:
        /my/special/foo  ->  ordinary/bar

Then the kernel replaces "foo" with "ordinary/bar" and you get
"/my/special/ordinary/bar".

And of course:
        /my/special/foo  ->  ../../your/handy/bar

replaces "foo" with "../../your/handy/bar" yielding
"/my/special/../../your/handy/bar", or just "/your/handy/bar".


One last thing: it is NOT necessary that the target of a symlink exist!
Just because you can create the link without error doesn't meant that
the link can be resolved.  In fact a number of programs use this feature
to good advantage, since creating a symlink is an atomic operation on
the filesystem, for creating lock files, etc. where the target of the
symlink is not a file at all, but rather some useful information related
to the lock (etc.)  If the information you want to keep is small this is
MUCH more efficient than open/write/close for a real file: it's one
(atomic) system call.

Anyway.  Symlinks rule!  :-)

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]