X Tutup
The Wayback Machine - https://web.archive.org/web/20201123153613/https://github.com/shelljs/shelljs/pull/665
Skip to content
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

ls -L (follow symlinks) #665

Merged
merged 7 commits into from Feb 28, 2017
Merged

ls -L (follow symlinks) #665

merged 7 commits into from Feb 28, 2017

Conversation

@frandiox
Copy link
Contributor

@frandiox frandiox commented Feb 23, 2017

This closes #563

I added some tests for -L option and fixed the other.

@nfischer If I'm not mistaken, there is a difference between bash's ls -R and shelljs's related to dir symlinks. Bash only shows the symlink itself but shelljs shows the direct children as well (1 level). In this case, ls -RL will show all the levels, not only the first one.

By the way, I think this test is a mistake since it is just a copy of another one, so I removed it.

@frandiox
Copy link
Contributor Author

@frandiox frandiox commented Feb 23, 2017

@nfischer Perhaps the difference I pointed out only happens in my local environment? Tests pass:

  463 passed
   1 skipped

Not sure how to proceed 😅

src/ls.js Outdated
@@ -60,7 +62,7 @@ function _ls(options, paths) {
relName = relName.replace(/\\/g, '/');
}
if (options.long) {
stat = stat || fs.lstatSync(abs);
stat = stat || options.link ? fs.statSync(abs) : fs.lstatSync(abs);

This comment has been minimized.

@freitagbr

freitagbr Feb 23, 2017
Contributor

I think you need to put the ternary in parentheses:

stat = stat || (options.link ? fs.statSync(abs) : fs.lstatSync(abs));

Otherwise the condition for the ternary is stat || options.link.

@frandiox
Copy link
Contributor Author

@frandiox frandiox commented Feb 24, 2017

@freitagbr @nfischer Appveyor is using a Windows environment, now I understand the difference 😅
I'm not sure how the tests should work for Windows since there are no symlinks there.
By the way, about the issue I mentioned in the OP

If I'm not mistaken, there is a difference between bash's ls -R and shelljs's related to dir symlinks. Bash only shows the symlink itself but shelljs shows the direct children as well (1 level). In this case, ls -RL will show all the levels, not only the first one.

I just reported it with a screenshot on #666
This issue is related to the failing tests as well because since ShellJS follows symlinks 1 level even without -L, I had to add +3 entries to some tests while normally only +1 would be enough (the symlink itself, not its children). That would pass in Windows I guess.

@nfischer
Copy link
Member

@nfischer nfischer commented Feb 26, 2017

@frankdiox this is a relatively small change that affects a lot of test cases. Do you think there's any way we could make this affect fewer test cases?

What if we do ls -RAL resources/rm/link_to_a_dir/ instead? We won't have to change any resource files, so we won't have to touch any other test cases. Would that work for testing this feature?

@nfischer
Copy link
Member

@nfischer nfischer commented Feb 26, 2017

That change would fix most of the breaking test cases on Windows.

I would expect we'll still have one breaking test case on Windows, because it handles symlnks differently than unix does. If that's the case, would it make sense to skip this test only for Windows? Here's an example of how we test unix-only code.

@frandiox frandiox mentioned this pull request Feb 26, 2017
@frandiox
Copy link
Contributor Author

@frandiox frandiox commented Feb 26, 2017

@nfischer Yep, I didn't see there was another symlink in resources/rm so I just created a new one under resources/ls. I reverted the latest test commit and made a new one using the existing symlink. It should be fine now 👍

Copy link
Member

@nfischer nfischer left a comment

@frankdiox Thanks for the hard work! This LGTM

@nfischer
Copy link
Member

@nfischer nfischer commented Feb 26, 2017

Deferring to @freitagbr for final approval

@freitagbr
Copy link
Contributor

@freitagbr freitagbr commented Feb 28, 2017

LGTM too.

@freitagbr freitagbr merged commit df06ac4 into shelljs:master Feb 28, 2017
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.
X Tutup