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

Unclosed file handle on futimes error #271

Closed
chadnickbok opened this issue Sep 9, 2016 · 9 comments
Closed

Unclosed file handle on futimes error #271

chadnickbok opened this issue Sep 9, 2016 · 9 comments

Comments

@chadnickbok
Copy link

The call to fs.close(fd) should be performed before the call to return in this function:

https://github.com/jprichardson/node-fs-extra/blob/master/lib/util/utimes.js#L53

@hhamilto
Copy link
Contributor

Unless anyone is working on this, I'll submit a PR.

@jprichardson
Copy link
Owner

Unless anyone is working on this, I'll submit a PR.

Would love this. Please include a test. Thanks!

@hhamilto
Copy link
Contributor

Please include a test.

Will do. I think there might be a few different ways to test this, so once the PR is up, I'll welcome some feed back on the best approach.

@hhamilto
Copy link
Contributor

@jprichardson Question:
How do you feel about adding a devDependency on Sinon, or some other mocking library?

Background:
I'm thinking that mocking would be the best way to test that close is properly called even when the call to futimes returns an error. The only errors that futimes usually returns occur when the fd passed in refers to a file on a read-only file system, or if the owner of the file doesn't match the current user (from here). It doesn't seem practical to set up either of these conditions just for a test, unless I missed something when researching.

If we mocked the fs functions that utimesMillis uses, then we could just assert that the close method is called even when futimes returns an error.

@jprichardson
Copy link
Owner

@hhamilto how do you feel about proxyquire?

hhamilto added a commit to hhamilto/node-fs-extra that referenced this issue Oct 15, 2016
hhamilto added a commit to hhamilto/node-fs-extra that referenced this issue Oct 15, 2016
hhamilto added a commit to hhamilto/node-fs-extra that referenced this issue Oct 15, 2016
@RyanZim
Copy link
Collaborator

RyanZim commented Oct 25, 2016

@hhamilto How's that PR coming along?

@hhamilto
Copy link
Contributor

@ryan I'd welcome your feedback on it:
#289

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 25, 2016

Sorry, didn't realize a PR was filed.

@hhamilto
Copy link
Contributor

No worries, I meant to put a ping on it a while back, to see if there is anything else that needs to be fixed before it gets merged.

jprichardson added a commit that referenced this issue Oct 25, 2016
(Closes #271) lib/util/utimes: properly close file descriptors in the event of an error
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

No branches or pull requests

4 participants