19 Mar 2008 jtauber   » (Master)

Inconsistent Symlinks

Set up directories as follows:

drwxr-xr-x   2 jtauber  staff   68 Mar 18 17:57 A
drwxr-xr-x   3 jtauber  staff  102 Mar 18 17:58 B
lrwxr-xr-x   1 jtauber  staff    3 Mar 18 17:58 C -> B/C

Now cd into B

jtmbp:TEST jtauber$ cd B

If you try to "execute" A from here, it tells you it's a directory

jtmbp:B jtauber$ ../A
-bash: ../A: is a directory

Now go back to the top directory

jtmbp:B jtauber$ cd ..

and cd into C (the symlinked directory)

jtmbp:TEST jtauber$ cd C

If you try to execute A from here, it can't find it via "../A" only "../../A"

jtmbp:C jtauber$ ../A
-bash: ../A: No such file or directory
jtmbp:C jtauber$ ../../A
-bash: ../../A: is a directory

so the attempt at execution is based on the actual absolute path, not the path based on following the symlink.

However,

jtmbp:C jtauber$ cd ../A
jtmbp:A jtauber$ 

So cd uses the path based on following the symlink but relative paths for execution do not.

I realise this is likely because cd is shell-based (and so knows the path that was followed to get to the current directory) whereas execution is a system call (which doesn't know the path that was followed to get to the current directory) but it's interesting nevertheless (and occasionally annoying).

This is on OS X but the behaviour is the same on Linux as far as I know.

Syndicated 2008-03-18 18:12:42 (Updated 2008-03-18 18:12:43) from James Tauber

Latest blog entries     Older blog entries

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!