-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
fs.watchFile inconsistent stat return #15364
Comments
The node.js documentation doesn't mention it but that's the correct and expected behavior for If the mtime is the same, the file was moved rather than created anew. If you get a callback with an all-fields-zero stats object, the next callback is a signal that the file has reappeared. I'll add documentation labels. |
Thank you for the quick response. |
Hey @bnoordhuis, I can pick this up if that's okay. Through what I understand from the discussion above and my own examination of the behavior mentioned, I need to add a Note at the bottom of this section, is that correct? Please let me know if there is anything I need to keep in mind. Meanwhile, I'll get started on this. Thanks! |
The expected behaviour of When a watched file reappears either because it was deleted and recreated or simply renamed twice (back and forth), the previous stat object should definitely be zero-ed. Just try putting yourself in the shoes of someone supervising the file. The only certainty stated by documentation is
All other properties are uncertain, so this is the only real check that the programmer can make. But the way |
➡️ Also mind that |
@NiveditN Yes, that's right.
@acarstoiu |
Doesn't matter, the discussion was about |
Yes... you were the one who brought up |
I'll say it more clearly: read and comment my arguments against your dismissal of this ticket as a documentation bug (when in fact it's an implementation issue). |
I've outlined why it's working as expected per the current implementation, which goes back to node.js v0.6 and behaved mostly identical even before that. Your comment starts off with "The expected behaviour of fs.watchFile() is..." when in fact that's merely your expectation. |
By "expected" I meant what is presumable, sane and efficient. If you deem the legacy behaviour as being "expected" in all cases, then you're effectively denying improvements. Also, this doesn't seem at all an awfully breaking change. In fact, nothing bad happens with the code implemented as advised by you (i.e. retain state also in client code), it will just be more suboptimal than it is right now. |
Undocumented doesn't mean unused. If you still think your suggestion is a good idea, open a pull request and argue your case. |
Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. Fixes: nodejs#15364
Note was previously mistakenly added under fs.appendFile() section. Now moved to correct position, under fs.watchFile(). The note explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. Fixes: nodejs#15364
Removed last paragraph, as per suggestions. The note explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. Fixes: nodejs#15364
Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. PR-URL: nodejs/node#16099 Fixes: nodejs/node#15364 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. PR-URL: #16099 Fixes: #15364 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. PR-URL: #16099 Fixes: #15364 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. PR-URL: #16099 Fixes: #15364 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. PR-URL: #16099 Fixes: #15364 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Hi!
I encountered the following problem when using fs.watchFile. I start watching a file, let's say file1, the file is renamed into file2 and then back into file1.
On the first rename, my listener is called with currentStat filled with 0s (correct, as the file does not exist) and some values for the previousStat.
On the second rename, when the file gets the name it had initially, the previousStat is the same one as the previousStat of the first rename (I think it should be the one filled with 0s, as the file did not exist previously) and has the same modified time as the currentStat. This way, I cannot determine that the file has reappeared.
I am comparing that the modified time has changed in order to avoid false alarms triggered by file access as specified in the Node.js documentation.
The text was updated successfully, but these errors were encountered: