Skip to content

ls -L (follow symlinks)#665

Merged
freitagbr merged 7 commits intoshelljs:masterfrom
frandiox:master
Feb 28, 2017
Merged

ls -L (follow symlinks)#665
freitagbr merged 7 commits intoshelljs:masterfrom
frandiox:master

Conversation

@frandiox
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

@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
}
if (options.long) {
stat = stat || fs.lstatSync(abs);
stat = stat || options.link ? fs.statSync(abs) : fs.lstatSync(abs);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Copy Markdown
Contributor Author

@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
Copy Markdown
Member

@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
Copy Markdown
Member

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
Copy Markdown
Contributor Author

@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
Copy Markdown
Member

@nfischer nfischer left a comment

Choose a reason for hiding this comment

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

@frankdiox Thanks for the hard work! This LGTM

@nfischer
Copy link
Copy Markdown
Member

Deferring to @freitagbr for final approval

@freitagbr
Copy link
Copy Markdown
Contributor

LGTM too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: ls -L option

3 participants