An initial option, like chokidar, would be nice
nono opened this issue · comments
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
- Followed all applicable steps in the debugging guide: http://flight-manual.atom.io/hacking-atom/sections/debugging/
- Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
- Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
- Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
Description
chokidar sends add
events for files and directories viewed on the initial scan. There is an option ignoreInitial
to avoid doing it. It'd be nice to have an initial
option for @atom/watcher
to do the default behavior of chokidar on this aspect. It's particularly useful on linux where the watcher is already browsing the tree to tell inotify what directories to watch, as it would avoid to have to do it again outside of the watcher (it would costs more syscalls and introduces risk of race conditions).
Steps to Reproduce
const w = await watcher.watchPath('/var/log', { initial: true }, events => { /* ... */ })
- [and so on...]
Expected behavior:
It sends an event for the existing files and directories inside /var/log
.
Actual behavior:
Nothing currently.
Versions
Master
Additional Information
It's a suggestion of an improvement, not a bug report.
By the way, I've opened the same issue for NSFW: Axosoft/nsfw#60
I'm 👍 on having this, although we likely won't need this for Atom itself so I'm less likely to jump on it 😄
The tricky bits here are dealing with race conditions - the filesystem may be modified concurrently with the initial scan, so it's tricky to keep the events we emit consistent.
although we likely won't need this for Atom itself so I'm less likely to jump on it
I've restarted work on the tree-view watchPath PR and I'm thinking that this would be nice so that the initial watchPath call can give the current directory structure rather than having to do a recursive fs.readdir
. (Then again, there might be an easier way to do this than the way I'm trying to right now that won't necessitate an initial option.)
I believe the way Chokidar solves this is by comparing the timestamp of the files/folders with the time at which the watcher is initialized. Items created after the watcher initialization are moved into a separate buffer, which are emitted after the ready event.
Even simpler thing to do would be to just emit mtime for the items along with the event.
Bump.
I'd love it if @atom/watcher
had an initial
option.
I'm trying to make an in-RAM model of all the files on a hard drive, and an initial
option would be the best way to do that.
I'd love it if anyone has any ideas for work-arounds.
Thank you!