Repository navigation
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.wontfixIssues that will not be fixed.
Description
- Affected versions: Latest release of Current and all LTSes - 11.6.0, 10.15.0, 8.15.0, and 6.16.0.
- Affected platform: Linux (ok on macOS/Windows)
- Subsystem: fs
Description
When using fs.watch() to watch a directory, and removing that very directory itself, a change event is emitted with a filename matching the directory itself.
To my knowledge, the standard way to obtain an absolute path of the affected file, is to path.join() the filename with the directory being watched.
As such, the emitted event is interpreted as if a subdirectory changed, which is incorrect.
Test case
Code at https://github.com/Krinkle/sandbox/blob/node-fs-watch-removedir/test.js.
Build output:
- Linux / Node 11.6.0: https://travis-ci.com/Krinkle/sandbox/jobs/167657972
- Linux / Node 10.15.0: https://travis-ci.com/Krinkle/sandbox/jobs/167657973
- .. for Node 8, 6 and macOS/Windows, see https://travis-ci.com/Krinkle/sandbox/builds/96013157.
In brief:
- Given a directory structure as follows:
- home/
- a/
- file1
- b/
- file1
- file2
- c/
- And creating an fs.FSWatcher for
home/andhome/c, viafs.watch(dir, { encoding: 'utf8', recursive: false }). - And removing
home/c/viafs.rmdirSync(dir).
Expected
Change event for home/ or home/c/. Specifically, one or more of:
- An event on
home/with a filename of'c','/c', or no filename. - An event on
home/c/with a filename of''(empty string),'.'(empty string),'/', or no filename.
Actual
On macOS, gets a change event for home/c/ as expected:
- FSWatcher for
home/receiveschangeevent; eventType=rename, filename=c
On macOS, gets a change event for home/c/ as expected:
- FSWatcher for
home/receiveschangeevent; eventType=rename, filename=c
On Linux, gets change events for /home/c/c/: ❌
- FSWatcher for
home/c/receiveschangeevent; eventType=rename, filename=c❌ - FSWatcher for
home/c/receiveschangeevent; eventType=rename, filename=c❌ - FSWatcher for
home/receiveschangeevent; eventType=rename, filename=c✅
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.wontfixIssues that will not be fixed.
Activity
bnoordhuis commentedon Jan 8, 2019
I can confirm the behavior you're seeing and while I agree it's inconvenient, I don't think this is really fixable. Libuv bubbles up the events it receives from the operating system mostly unfiltered.
On macos, it receives just one event. On linux, it receives three. I tried a couple of things but filtering out the first two introduces more issues than it fixes.
bnoordhuis commentedon Jan 23, 2019
There's been no further discussion in the last two weeks so I'll take the liberty of closing this out. Thanks anyway for the bug report.