-
Notifications
You must be signed in to change notification settings - Fork 7.3k
fs: deprecate exists() and existsSync() #8418
Conversation
// If the callback is passed more than one argument, then call back | ||
// with error and exists. Otherwise, use the legacy behavior, and only | ||
// call back with exists. | ||
if (callback.length > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 because callback.length
may have a big performance problem :(
http://jsperf.com/function-length-performance/8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest access to node version like useErrback = version > '0.10.32'
cached at initialize stage, and here we just get: if (useErrback)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That performance hit is ugly. There is no point in checking the node version though. I guess there are a few options.
- Do nothing and close this PR. This function isn't recommended for use anyway.
- Take the performance hit, maintain backward compatibility, and support both styles (current implementation).
- Introduce a breaking change and support only the errback style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or officially deprecate this function, and remove it from documentation (maybe add fs.access
instead)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rlidwka +1
Good potential idea, and that is a safe way to address the deprecation cycle Node uses. Though whether we actually add similar behavior back in is debatable. The only slight potential use is to try to avoid throwing when opening a file synchronously. But that is essentially a race condition, and I don't believe Node should natively support a workflow that allows that type of behavior. @cjihrig Mind updating the PR and simply deprecating |
@trevnorris I've updated the PR to deprecate those methods. I also had to update |
@@ -641,6 +641,8 @@ callback, and have some fallback logic if it is null. | |||
|
|||
## fs.exists(path, callback) | |||
|
|||
This function is **deprecated**. Use [fs.open()][] instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of the. "Use ... instead". The user should be able to figure out what they need to be doing. :)
Nice. One little nit, other than that LGTM. @tjfontaine Thoughts on properly deprecating |
@trevnorris updated |
I'm going to kibbitz just a tiny bit and say to @trevnorris that I don't think the world will explode if there's a hint or two in the documentation towards what people might want to use instead of the deprecated functions. A lot of people really don't know what they're supposed to do instead of use |
@othiym23 fs functions tend to align with POSIX, maybe adding fs.access (which uses |
I can certainly try. I will likely need some guidance from @saghul if there is a libuv component that needs to be implemented. |
@cjihrig yeah, we'll need some
On Unix this would be a thin wrapper on top of Feel free to ping me if you need help. |
@saghul would you mind taking a quick look at this commit? It's just the Unix side of things, but wanted to make sure I was on the right track. Thanks. |
@cjihrig looks solid, keep up the good work :-) Also extra karma for adding docs without me complaining about it! 👍 |
Left a comment about implementation details. @saghul you'll probably want to chime in on the correct approach. |
Left a comment there myself. @cjihrig please open a PR on libuv, you are halfway there already :-) About the use of Either way, in this case using
(adapted from CPython's source) Those defines should probably be put on uv-win.h so Windows users get them when including uv.h. |
Indeed, we strongly prefer WIN32 or NTAPI functions over crt functions. As for the GetFileAttributesW suggestion - you should be aware that this is not a very effictive test whether the user has access to the file, because windows uses ACLs and not unix-style user/group/world permission. The other thing to be aware of is that a GetFileAttributesW under the opens the file, stat()s it, then closes it. A more reliable and faster strategy may be to just open the file with the desired permissions, and then close it again if it succeeds. The only issue there may become that a file could be locked by another process, in which case GetFileAttributesW might succeed (it only needs the FILE_READ_ATTRIBUTES permission which would typically be available), while CreateFile with one of the more extensive permission sets (FILE_GENERIC_READ, FILE_GENERIC_WRITE, GENERIC_EXECUTE) might not. I am not sure whether reporting "no access" when a file is locked is desirable or not. |
I guess it's ok.
Ouch, I wasn't aware of this :-/
Would this be bad if the user already has the file open?
I don't think so. In the end, this function needs to come with a big warning, because using this LBYL approach is race prone, whereas EAFP is not. |
@saghul Ah |
@trevnorris do you still want this for 0.12? If so, any timeline on #8566 landing? |
I'm not sure if I would do a full on deprecation of |
@cjihrig libuv has been updated to 1.0.0rc-2. |
@tjfontaine do you want to deprecate in 0.13 (or whatever comes after 0.12)? |
@cjihrig @trevnorris .... any reason to keep this open? |
No. People have asked for this to be deprecated. We deprecated it in io.js, and people asked for it to be un-deprecated. |
fs.exists()
does not currently support Node's standard callback signature. This commit adds errback support while maintaining backwards compatibility. Closes #8369.