Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

An initial option, like chokidar, would be nice #182

Open
1 task done
nono opened this issue Oct 24, 2018 · 5 comments
Open
1 task done

An initial option, like chokidar, would be nice #182

nono opened this issue Oct 24, 2018 · 5 comments

Comments

@nono
Copy link
Contributor

nono commented Oct 24, 2018

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.

@nono
Copy link
Contributor Author

nono commented Oct 26, 2018

By the way, I've opened the same issue for NSFW: Axosoft/nsfw#60

@smashwilson
Copy link
Contributor

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.

@50Wliu
Copy link

50Wliu commented Nov 10, 2018

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.)

@CxRes
Copy link

CxRes commented Jan 1, 2019

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.

@george-thomas-hill
Copy link

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants