#1085 ln -s does not work with relative target path

Cesar Strauss
MSYS (75)
Heiko Hund

Symlink creation does not work as expected when the target of the link is given relative to the source, but the current working directory is different from where the symlink is to be created, e.g.

$ mkdir a
$ mkdir -p b/c
$ cd a
$ touch d
$ ln -s ../../a/d ../b/c/d
ln: creating symbolic link `../b/c/d' to `../../a/d': No such file or directory

`../../a/d' is not found because the working directory is not changed to the one of the source `../b/c/d'. If you `ln -s d ../b/c/d` it works.

I have checked the source code in HEAD and think I might have found the spot where the copying is done incorrectly. msys/rt/src/winsup/cygwin/msys_symlink.cc line 157:

if (!CopyFile (w_frompath, w_topath, FALSE))

If this is really it, the bug could possibly be fixed by cutting 'w_topath' into 'dirname' and 'basename' and doing something like this:

GetCurrentDirectory(sizeof(*olddir), olddir);
CopyFile (w_frompath, basename, FALSE);

Would s.th. like that work?

System info:
Windows XP SP2
MSYS 1.0.11(0.46/3/2) 2007-07-29 17:16 i686 unknown; targ=MINGW32
GNU bash, version 2.04.0(1)-release (i686-pc-msys); ENV=.profile
GNU Make version 3.79.1,Built for i686-pc-msys; MAKE_MODE=unix
gcc.exe (GCC) 3.4.2 (mingw-special); targ=MINGW32
GNU ld version 2.15.91 20040904


  • Cesar Strauss
    Cesar Strauss

    This test case works from MSYS 1.0.12 onwards.

    Thanks for the report.


  • Cesar Strauss
    Cesar Strauss

    • status: open --> closed-fixed