From 8c070f9ed5dca4e402c69eb0c4901a1c28b99ec7 Mon Sep 17 00:00:00 2001 From: NiveditN Date: Mon, 9 Oct 2017 12:49:07 +0530 Subject: [PATCH] doc: added note to fs.watchFile on previousStat Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. PR-URL: https://github.com/nodejs/node/pull/16099 Fixes: https://github.com/nodejs/node/issues/15364 Reviewed-By: James M Snell Reviewed-By: Claudio Rodriguez Reviewed-By: Gireesh Punathil Reviewed-By: Ben Noordhuis --- doc/api/fs.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 08fbf62b9363cf..e61d1d11ea12d5 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1925,6 +1925,15 @@ you need to compare `curr.mtime` and `prev.mtime`. `fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and `fs.unwatchFile` when possible. +*Note:* When a file being watched by `fs.watchFile()` disappears and reappears, +then the `previousStat` reported in the second callback event (the file's +reappearance) will be the same as the `previousStat` of the first callback +event (its disappearance). + +This happens when: +- the file is deleted, followed by a restore +- the file is renamed twice - the second time back to its original name + ## fs.write(fd, buffer[, offset[, length[, position]]], callback)