Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursively watch newly created directories #1

Closed
mikemahony opened this issue Apr 21, 2017 · 3 comments
Closed

Recursively watch newly created directories #1

mikemahony opened this issue Apr 21, 2017 · 3 comments

Comments

@mikemahony
Copy link

Hi! Do you plan to support recursive watching of directories that are added after the root watch has started? And then, conversely, removing watchers when directories are deleted? Thanks!

@tywkeene
Copy link
Owner

Hi! So sorry it took so long to get back to you. For whatever reason I was not notified of this issue. My apologies.

Anyways, I think I've already done what you're talking about. If you look at the example in example/example.go, you can see that can react on events.

e..g:

	// Directory events
			if event.IsDirCreated() == true {
				log.Println("Directory created:", path.Clean(event.Path))
				if err := watcher.AddDescriptor(path.Clean(event.Path), 0); err != nil {
					panic(err)
				} else {
					log.Printf("Watch descriptor created and started for %s", event.Path)
				}
			}
			if event.IsDirRemoved() == true {
				log.Println("Directory removed:", path.Clean(event.Path))
				if err := watcher.RemoveDescriptor(path.Clean(event.Path)); err != nil {
					panic(err)
				} else {
					log.Printf("Watch descriptor removed for %s", event.Path)
				}
			}

Is this what you're thinking of? This would add watches for directories when they're created under the root, and delete them when removed.

Again, my apologies for the super late reply. I'm gonna go fix my notifications, and I will be sure to check back in case you, or anyone else has any questions.

@AxelWal
Copy link

AxelWal commented Jul 7, 2017

With AddDescriptor only the Watcher Event is not started .
My Solution is:

			if event.IsDirCreated() == true {
				log.Println("Directory created:", path.Clean(event.Path))
				watcher.AddDescriptor(path.Clean(event.Path), inotifyFlags)
				descriptor := watcher.GetDescriptorByPath(path.Clean(event.Path))
				descriptor.Start(watcher.FileDescriptor)

			}

```After creating the Directory the Notify is directly started.

@tywkeene
Copy link
Owner

tywkeene commented Jul 7, 2017

@AxelWalsleben is right, I should read my own code.

Using AddDescriptor() the watch isn't started, you have to manually start it.

If I remember correctly (it's been a while), I did this because I was getting some really weird events that didn't seem to be valid when starting a lot of descriptors at once.

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

No branches or pull requests

3 participants