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

adding Unwatch function for file provider #245

Conversation

prateek-narsinghani
Copy link

No description provided.

providers/file/file.go Outdated Show resolved Hide resolved
providers/file/file.go Outdated Show resolved Hide resolved
@prateek-narsinghani
Copy link
Author

prateek-narsinghani commented Nov 9, 2023

@rhnvrm , I have made the following changes:

  1. Changed function name UnWatch -> Unwatch
  2. Added comment for the Unwatch function
  3. Using Close function for all the watchers
  4. Adding an array to the file structure as there can be multiple f.Watch() calls, hence an array would store all the watchers

@knadh
Copy link
Owner

knadh commented Nov 26, 2023

@prateek-narsinghani thanks for the PR. Could you please add tests for this as well?

@knadh knadh added the enhancement New feature or request label Nov 26, 2023
@prateek-narsinghani
Copy link
Author

prateek-narsinghani commented Dec 3, 2023

@knadh I have added a test for the Unwatch function. Let me know if any further changes are required.

providers/file/file.go Outdated Show resolved Hide resolved
providers/file/file.go Show resolved Hide resolved
@rhnvrm rhnvrm requested a review from knadh May 11, 2024 17:22
// Unwatch stops watching the files. It closes all the fsnotify watchers
// and event channels associated with them.
func (f *File) Unwatch() error {
return f.w.Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f.w = nil is missing here for the case of restart watching (there is checking for f.w != nil

os.WriteFile(tmpFile, []byte(`{"parent": {"name": "name2"}}`), 0600)
wg.Wait()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sequence of Watch/Unwatch/Watch needs to be checked

@knadh
Copy link
Owner

knadh commented Jul 17, 2024

I finally got around to looking into this. Please take a look at: #306

It addresses a couple of issues in this PR:

  • Unwatch() triggers random channel closure errors (main channel or error channel) to the callback, which the caller is expected to handle. Unwatch() shouldn't trigger these errors.
  • The f.w == nil issue where once Unwatched(), the watcher couldn't be used again. Also, setting f.w to nil would require locking.

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

Successfully merging this pull request may close these issues.

5 participants