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 doesn't follow links to directories #733

Closed
nfischer opened this issue Jun 7, 2017 · 5 comments
Closed

ls doesn't follow links to directories #733

nfischer opened this issue Jun 7, 2017 · 5 comments
Assignees
Labels
bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem

Comments

@nfischer
Copy link
Member

nfischer commented Jun 7, 2017

Originally reported as #446

Node version (or tell us if you're using electron or some other framework):

latest

ShellJS version (the most recent version/Github branch you see the bug on):

Latest. The bug was introduced in v0.7.0

Operating system:

Confirmed on both OS X and Linux.

Description of the bug:

Originally reported in #446. I'm branching this off, since that issue actually discusses two changes.

ls() doesn't follow symlinks pointing to directories, while ls does in Bash.

Example ShellJS command to reproduce the error:

// setup
shell.mkdir('real');
shell.touch('real/file1');
shell.touch('real/file2');
shell.ln('-s', 'real', 'sym');

shell.ls('real');      // file1, file2
shell.ls('sym');       // sym (this is a bug)
shell.exec('ls real'); // file1, file2 (bash behavior)
shell.exec('ls sym');  // file1, file2 (bash behavior)

@freitagbr can you investigate? We should bisect to find the commit that introduced this bug (possibly something from this list). From there, we can figure out how to fix this.

@nfischer nfischer added bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem labels Jun 7, 2017
@freitagbr
Copy link
Contributor

It has to do with the way files are handled, specificallly in pushFile. fs.lstatSync is used in the default case, which returns stats about the symbolic link itself, not the file or directory it links to. I think there needs to be extra handling for the case when stat.isSymbolicLink() is true. I will work on a fix.

@nfischer
Copy link
Member Author

@freitagbr were you able to bisect to a commit? Unix behavior can be somewhat inconsistent around here, so this bug probably arose as a side effect of another bug fix. It would be good to understand all the scenarios we need to account for.

@freitagbr
Copy link
Contributor

I will do the bisect tonight.

@freitagbr
Copy link
Contributor

freitagbr commented Jun 15, 2017

Ok, git bisect landed me at commit 3e441e4. I used a test script to help out:

$ mkdir real
$ touch real/a real/b
$ ln -s real sym
$ cat test-ls.js
var assert = require('assert');
var $ = require('./');
var result = $.ls('./sym');
assert(result.indexOf('a') > -1);
assert(result.indexOf('b') > -1);
$ git bisect master v0.5.0  # v0.5.0 is a known good revision
$ git bisect run node test-ls.js

Thus, the bug was introduced in commit b76a569. The commit description is refactor(ls): greatly simplify ls implimentation, so it makes sense that this would be the commit that introduced the bug.

@nfischer
Copy link
Member Author

That would be #369

@nfischer nfischer changed the title ls doesn't follow links to directories on OS X ls doesn't follow links to directories Jun 18, 2017
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