Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

How to handle "folders created/deleted after registration"? #44

Closed
ngocdaothanh opened this issue Jun 3, 2014 · 4 comments
Closed

How to handle "folders created/deleted after registration"? #44

ngocdaothanh opened this issue Jun 3, 2014 · 4 comments

Comments

@ngocdaothanh
Copy link

In README:

Callbacks that are registered with recursive=true are not persistently-recursive. That is, they do not propagate to new files or folders created/deleted after registration. Currently, the plan is to have developers handle this themselves in the callback functions.

Do you mean developers should unregister and register again inside the callback functions? Is there problem when concurrency > 1?

@lloydmeta
Copy link
Owner

Yes, the was the idea (register/unregister inside the callbacks). It shouldn't cause problems when concurrency > 1 because the concurrency is for the number of actors doing the callbacks, which is different from the MonitorActor that holds the registry of path+event-type -> callback functions :)

@ngocdaothanh
Copy link
Author

Thanks!

@pathikrit
Copy link

I think this worth reconsidering. Even Oracle's canonical example here: https://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
auto-registers a watcher on any new directories created inside the recursively watched directory.

Btw, I am the author of another implementation (https://github.com/pathikrit/better-files#file-watchers) of this based purely on Java threads:
https://github.com/pathikrit/better-files/blob/master/src/main/scala/better/files/FileMonitor.scala
Please take a look if you have any time for suggestions/reviews. Thanks!

@lloydmeta
Copy link
Owner

@pathikrit thanks for the note; I've starred your repo since a while ago :)

I can't remember why I had left that for end-users to handle, but theoretically it looks simple enough to implement:

// if directory is created, and watching recursively, then
                // register it and its sub-directories
                if (recursive && (kind == ENTRY_CREATE)) {
                    try {
                        if (Files.isDirectory(child, NOFOLLOW_LINKS)) {
                            registerAll(child);
                        }
                    } catch (IOException x) {
                        // ignore to keep sample readbale
                    }
                }

Just leaving a note on a possible implementation:

I think in this lib, this can be handled by having the watch path message (watchMsg1) have a autoWatchNew parameter that causes the actor to automatically register itself to file creation events down the file hierarchy in order to auto-register those for the same callback as in watchMsg1.

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

3 participants