Skip to content

Fix relative symlinks#282

Merged
nfischer merged 4 commits intoshelljs:masterfrom
freitagbr:fix-relative-symlinks
Jan 26, 2016
Merged

Fix relative symlinks#282
nfischer merged 4 commits intoshelljs:masterfrom
freitagbr:fix-relative-symlinks

Conversation

@freitagbr
Copy link
Copy Markdown
Contributor

Fixes #100

@freitagbr
Copy link
Copy Markdown
Contributor Author

I based this PR on Schoonology's fix (PR #235), removing the warning that is displayed when a symbolic link is created.

@nfischer
Copy link
Copy Markdown
Member

@freitagbr Could you check that this works under node v0.10? It seems to be failing on the CI.

@nfischer nfischer added fix Bug/defect, or a fix for such a problem medium priority labels Jan 11, 2016
@nfischer
Copy link
Copy Markdown
Member

Also, would you be able to squash the commits? See here

@freitagbr
Copy link
Copy Markdown
Contributor Author

The Node.js v0.10 path module does not have the isAbsolute method (it was added in Node v0.11). That is what is causing the build to fail.

@nfischer
Copy link
Copy Markdown
Member

The usual method we use is to check for its existence, and if it doesn't exist, use a workaround. Would that be feasible? That way we can use isAbsolute when it's available, and fall back to the alternative when necessary.

@freitagbr
Copy link
Copy Markdown
Contributor Author

As long as the source string does not start with a /, it is absolute. Simply checking source.indexOf('/') !== 0 should do the same thing, correct?

@nfischer
Copy link
Copy Markdown
Member

Will that play well with Windows? I think that should be sufficient for *nix though (unless ~ is supported)

@freitagbr
Copy link
Copy Markdown
Contributor Author

This should work as intended, though ~ is still not supported. It is trivial to add support, and I think it would be worthwhile. Thoughts?

@nfischer
Copy link
Copy Markdown
Member

I'm working on a PR for the tilde (currently unsupported), but there are some other big changes I want to get merged first. So don't add support for it just yet. Once we do, we'll have to add an "is absolute path" method that handles the tilde

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nfischer
Copy link
Copy Markdown
Member

Could you also add some invalid test cases toward the top?

# symlinks
mkdir -p tmp/
touch tmp/file1.txt
ln -sf tmp/file1.txt tmp/file2.txt
# make sure there was an error

mkdir -p tmp/
touch file1.txt
ln -sf file1.txt tmp/file2.txt
# make sure there was an error

# hardlinks
mkdir -p tmp/
touch tmp/file1.txt
ln -f file1.txt tmp/file2.txt
# make sure there was an error

@ariporad
Copy link
Copy Markdown
Contributor

@freitagbr: Any chance I could ask you to add the small changes? I'd really like to include this in the next release. Thanks!

@ariporad ariporad added this to the v0.6.0 milestone Jan 24, 2016
@freitagbr
Copy link
Copy Markdown
Contributor Author

@ariporad Will do! I'll have this done by the end of the day.

@nfischer
Copy link
Copy Markdown
Member

👍 @freitagbr just ping this thread when you have the tests merged in and I'll review

@ariporad
Copy link
Copy Markdown
Contributor

@freitagbr: Thanks, but no rush!

Ari

On Sun, Jan 24, 2016 at 2:41 PM, Nate Fischer notifications@github.com
wrote:

[image: 👍] @freitagbr https://github.com/freitagbr just ping this
thread when you have the tests merged in and I'll review


Reply to this email directly or view it on GitHub
#282 (comment).

When creating a symlink with a relative path, e.g. `ln('-s', '../baz.txt', 'foo/bar/link')`,
the link will be created releative to the destination directory, not to the
current working directory of the node process. Also added tests for
functionality.
@nfischer
Copy link
Copy Markdown
Member

@freitagbr then my only other comment is the invalid test cases (#282 (comment)). Once those are in, this'll be good!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testing, I found that the source file was not checked properly for hard links. This correctly checks if the source exists for hard links.

@nfischer
Copy link
Copy Markdown
Member

@freitagbr nice work!

LGTM

@ariporad
Copy link
Copy Markdown
Contributor

👍

nfischer added a commit that referenced this pull request Jan 26, 2016
@nfischer nfischer merged commit 24c2120 into shelljs:master Jan 26, 2016
@freitagbr freitagbr deleted the fix-relative-symlinks branch January 26, 2016 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug/defect, or a fix for such a problem medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants