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

Use fs.lstat for checking if file is a directory #8

Closed
wants to merge 2 commits into from

Conversation

sheerun
Copy link
Contributor

@sheerun sheerun commented Oct 14, 2015

Instead of relying on ENOTDIR exceptions.

This fixes weird behavior of Windows when using NFS. In such environment
fs.readdir returns ENOENT instead of ENOTDIR for normal files. This
causes chmodr to fail on the first file. This commit changes
implementation to straightforward checking if path is directory, so it
works on all platforms and filesystems.

Because there are usually more files than directories to chmod,
this is also more performant solution, as it avoids triple system call
for files (fs.readdir, fs.lstat, fs.chmod becomes fs.lstat, fs.chmod),
and uses truple and instead uses triple system call for directories
(fs.readdir, fs.chmod becomes fs.lstat, fs.readdir, fs.chmod).


This commit is a result of debugging failing bower tests on Windows. After this change the the test changing read-only permissions and removing .git directory is passing in VM environment (Parallels Desktop 11 on OSX). I hope you'll find time to review it and release it, so I can update bower as well.

Instead of relying on ENOTDIR exceptions.

This fixes weird behavior of Windows when using NFS. In such environment
fs.readdir returns ENOENT instead of ENOTDIR for normal files. This
causes chmodr to fail on the first file. This commit changes
implementation to straightforward checking if path is directory, so it
works on all platforms and filesystems.

Because there are usually more files than directories to chmod,
this is also more performant solution, as it avoids triple system call
for files (fs.readdir, fs.lstat, fs.chmod  becomes  fs.lstat, fs.chmod),
and uses truple  and instead uses triple system call for directories
(fs.readdir, fs.chmod  becomes  fs.lstat, fs.readdir, fs.chmod).
throw er
var stats = fs.lstatSync(p)
if (stats.isSymbolicLink())
return;

Choose a reason for hiding this comment

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

I think it'd be better to either use braces or make it a one-liner to keep style consistent with the rest of the file. Not sure if important, but figured I'd point it out (':

@yoshuawuyts
Copy link

Looks like your reasoning is sound, tests are passing and weren't modified so lgtm 👏. Also: I think dropping 0.8.x support would be fine since it's no longer maintained anyway.

sheerun added a commit to bower/bower that referenced this pull request Oct 14, 2015
Sometimes it return ENOENT instead of ENODIR for normal files.

This broke code paths in few places. Also, see:
isaacs/chmodr#8
@isaacs
Copy link
Owner

isaacs commented Oct 14, 2015

I landed this on master, updated the travis-ci file to be more modern, and then made some style changes. Thanks for the patch!

@isaacs isaacs closed this Oct 14, 2015
@sheerun
Copy link
Contributor Author

sheerun commented Oct 15, 2015

Maybe we should also fix this behaviour in graceful-fs?

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.

3 participants