You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fs.exists is infamous for having an inconsistent non-nodeback API that confuses new users often and can be a pain spot.
I see two good alternatives:
Deprecate it, mark it as deprecated in the docs and suggest fs.stat instead + discuss the inherent problem with using exists (race condition). Add a big warning. Optionally console.log a deprecation notice when the server is first started.
Change the API to return a nodeback. I like this idea less since it'd have to be written in a way that wouldn't break current code. This sounds harder and less optimal.
Personally I'm for the first. Let's clean up fs :)
I am pleased to see your valuable contribution to this project. Would you
please mind answering a couple of questions to help me classify this submission
and/or gather required information for the core team members?
Questions:
Issue-only Does this issue happen in core, or in some user-space
module from npm or other source? Please ensure that the test case
that reproduces this problem is not using any external dependencies.
If the error is not reproducible with just core modules - it is most
likely not a io.js problem. Expected: yes
Which part of core do you think it might be related to? One of: tls, crypto, buffer, http, https, assert, util, streams, smalloc, cluster, child_process, dgram, c++, docs, other (label)
Which versions of io.js do you think are affected by this? One of: v0.10, v0.12, v1.0.0 (label)
Please provide the answers in an ordered list like this:
Answer for the first question
Answer for the second question
...
Note that I am just a bot with a limited human-reply parsing abilities,
so please be very careful with numbers and don't skip the questions!
In case of success I will say:...summoning the core team devs!.
In case of validation problem I will say:Sorry, but something is not right here:.
I am pleased to see your valuable contribution to this project. Would you
please mind answering a couple of questions to help me classify this submission
and/or gather required information for the core team members?
Questions:
Issue-only Does this issue happen in core, or in some user-space module from npm or other source? Please ensure that the test case that reproduces this problem is not using any external dependencies. If the error is not reproducible with just core modules - it is most likely not a io.js problem. Expected: yes
Which part of core do you think it might be related to? One of: tls, crypto, buffer, http, https, assert, util, streams, smalloc, cluster, child_process, dgram, c++, docs, other (label)
Which versions of io.js do you think are affected by this? One of: v0.10, v0.12, v1.0.0 (label)
Please provide the answers in an ordered list like this:
Answer for the first question
Answer for the second question
...
Note that I am just a bot with a limited human-reply parsing abilities,
so please be very careful with numbers and don't skip the questions!
In case of success I will say: ...summoning the core team devs!.
In case of validation problem I will say: Sorry, but something is not right
here:.
Truly yours,
Caine.
Responsibilities
indutny: crypto, tls, https, child_process, c++
trevnorris: buffer, http, https, smalloc
bnoordhuis: http, cluster, child_process, dgram
—
Reply to this email directly or view it on GitHub.
fs.exists() should not be used to check if a file exists before calling fs.open(). Doing so introduces a race condition since other processes may change the file's state between the two calls. Instead, user code should call fs.open() directly and handle the error raised if the file is non-existent.
Activity
rvagg commentedon Dec 6, 2014
Yes! Option 1 is my vote. This is a tiny black spot on the Node fs API.
cjihrig commentedon Dec 7, 2014
+1 for deprecating. This was already being discussed in nodejs/node-v0.x-archive#8418.
fs.access()an alternative is also up for PR nodejs/node-v0.x-archive#8714. Since both of those are mine, I'd be glad to do the work here.ghostbar commentedon Dec 7, 2014
+1 on option 1.
juliangruber commentedon Dec 7, 2014
👍 for deprecating
bnoordhuis commentedon Dec 7, 2014
Sounds reasonable. @cjihrig Go for it.
benjamingr commentedon Dec 7, 2014
@cjihrig yes please! The fix looks pretty solid and so far everyone is for deprecating it.
fengmk2 commentedon Dec 7, 2014
@cjihrig 👍 here
indutny commentedon Dec 8, 2014
Summoning @caineio
caineio commentedon Dec 8, 2014
Hello!
I am pleased to see your valuable contribution to this project. Would you
please mind answering a couple of questions to help me classify this submission
and/or gather required information for the core team members?
Questions:
module from npm or other source? Please ensure that the test case
that reproduces this problem is not using any external dependencies.
If the error is not reproducible with just core modules - it is most
likely not a io.js problem. Expected:
yesOne of:
tls, crypto, buffer, http, https, assert, util, streams, smalloc, cluster, child_process, dgram, c++, docs, other(label)One of:
v0.10, v0.12, v1.0.0(label)Please provide the answers in an ordered list like this:
Note that I am just a bot with a limited human-reply parsing abilities,
so please be very careful with numbers and don't skip the questions!
In case of success I will say:
...summoning the core team devs!.In case of validation problem I will say:
Sorry, but something is not right here:.Truly yours,
Caine.
Responsibilities
benjamingr commentedon Dec 8, 2014
indutny commentedon Dec 8, 2014
@caineio what's up with you? Why are you ignoring this?
5 remaining items
fs: deprecate exists() and existsSync()
cjihrig commentedon Dec 19, 2014
fs.exists()andfs.existsSync()are deprecated as of 5678595benjamingr commentedon Dec 19, 2014
Awesome news :) Thanks a ton.
fs: undeprecate exists() and existsSync()
matthew-dean commentedon Apr 30, 2015
I am sad at this deprecation.
captn3m0 commentedon May 3, 2015
We have an npm module now: https://github.com/sindresorhus/path-exists
Use path-exists instead of fs.exists.
xixixao commentedon Oct 10, 2015
/facepalm How was this not sufficient:
matthew-dean commentedon Oct 10, 2015
Because I don't want to open the file.
Fishrock123 commentedon Oct 10, 2015
Please see: #1592