From 06f2eaeffd65887ec4181a594d1f2a7a98a1f0cf Mon Sep 17 00:00:00 2001 From: NiveditN Date: Mon, 9 Oct 2017 12:49:07 +0530 Subject: [PATCH 1/3] doc: added note to fs.watchFile on previousStat Explains the expected behavior of previousStat in fs.watchFile() when a watched file disappears and reappears. Fixes: https://github.com/nodejs/node/issues/15364 --- doc/api/fs.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 0c91ec7b352722..ecab0d5afec379 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -626,6 +626,19 @@ Any specified file descriptor has to have been opened for appending. *Note*: If a file descriptor is specified as the `file`, it will not be closed automatically. +*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 + +In such cases the reappearance callback will not report the `previousStat` of +the file with all zeroes. This is the correct and expected behavior for +`uv_fs_poll_start()`, the libuv function that `fs.watchFile()` uses internally. + ## fs.appendFileSync(file, data[, options])