Skip to content

Symlinking into a directory does not work #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
loilo opened this issue Apr 5, 2018 · 3 comments
Open

Symlinking into a directory does not work #832

loilo opened this issue Apr 5, 2018 · 3 comments
Labels
bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem

Comments

@loilo
Copy link

loilo commented Apr 5, 2018

Node version:

9.10.1

ShellJS version:

0.7.8

Operating system:

Tested on macOS 10.13.2 and Ubuntu 14.04.5 LTS

Description of the bug:

If the destination of the ln command is an existing directory, shelljs will fail stating that the Destination file exists.

However, according to tests in the mentioned environments, the correct behaviour would be to put a symlink with the source's name into that destination directory.

Example ShellJS command to reproduce the error:

The following commands fail, they should instead create a symlink to /some/source/path as ./path.

shelljs.ln('-s', '/some/source/path', '.')

or

shx ln -s /some/source/path .
@nfischer
Copy link
Member

nfischer commented Apr 5, 2018

Hmm, it works if I use:

shelljs.ln('-s', '/some/source/path', 'nameForLink');

It looks like ln should behave like cp: if the last argument is an existing-directory, then the link should be created inside that directory and the link name should default to the name of the thing it points to.

Concretely, it should look like this:

$ ln -s path/to/file.txt thisFolderExists
# there's a link named thisFolderExists/file.txt

$ ln -s path/to/file.txt thisDoesNotExist
# there's a link named 'thisDoesNotExist', which points to 'path/to/file.txt'

$ ln -s path/to/file.txt thisRegularFileExists
ln: failed to create symbolic link 'thisRegularFileExists': File exists

@nfischer nfischer added the fix Bug/defect, or a fix for such a problem label Apr 5, 2018
@loilo
Copy link
Author

loilo commented Apr 5, 2018

Yep, that's pretty much what I described.

One thing to mention though (which I figured out while implementing the attached pull request): The name in fact does not default to the source pointed to, but the basename you provided.

By Example:

Assume the following directory tree:

a/
└── b/
    └── c/

If we are in c/ and run ln -s . ../.., we'd expect to get a symlink named c, located inside a, pointing to c.

This is, in fact, not the case. The command will fail with ln: failed to create symbolic link '../../.': File exists.

That leads me to assume that the default name is actually the basename from the user-provided source path.

@nfischer
Copy link
Member

nfischer commented Apr 6, 2018

is actually the basename from the user-provided source path.

Seems reasonable. ln -s is kind of funky in that respect.

@nfischer nfischer added the bash compat Compatibility issues with bash or POSIX behavior label Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy