Skip to content

Symbolic links are broken! #100

@nylen

Description

@nylen

The new ln function does not work correctly in some cases:

# Setup
mkdir test-shelljs-ln
cd test-shelljs-ln
mkdir -p dir1/dir2/
echo file1_contents > dir1/file1.txt

# Create a link the old-fashioned way
ln -s ../file1.txt dir1/dir2/link1

# Create a link the new way
npm install 'shelljs@git://github.com/arturadib/shelljs.git#284fc1cc34'
node -e "require('shelljs').ln('-s', '../file1.txt', 'dir1/dir2/link2');"
# shelljs prints this error message:
#ln: Source file does not exist

# Inspect the results
ls -la dir1/dir2/
# output contains the following:
#lrwxrwxrwx 1 me me   12 Dec 27 22:47 link1 -> ../file1.txt
#lrwxrwxrwx 1 me me   32 Dec 27 22:49 link2 -> /home/me/file1.txt

# Clean up
cd ..
rm -r test-shelljs-ln

So, there are a couple of problems here:

  • The source of a symbolic link doesn't have to exist relative to the current directory.
  • The source of a symbolic link shouldn't be resolved relative to the current directory. If you really want to check for the existence of the source file, resolve the source path relative to the destination directory, but POSIX ln doesn't do this.

The second issue prevents relative links from being created. The link2 created by shelljs above points to a file that does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions