atom / watcher

Atom Filesystem Watcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An initial option, like chokidar, would be nice

nono opened this issue · comments

Prerequisites

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

  1. const w = await watcher.watchPath('/var/log', { initial: true }, events => { /* ... */ })
  2. [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!