Fix watcher stopping after atomic file saves#433
Open
PranjaliBhardwaj wants to merge 1 commit into
Open
Conversation
Signed-off-by: Pranjali Bhardwaj <pranjalisharma6543@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This fixes an issue where microcks import --watch stops detecting file changes after the first save when using editors like VS Code.
The problem happens because many editors use atomic saves internally (write temp file + rename), which causes fsnotify to emit Rename/Remove events and drop the existing watch on the original file.
Changes
Expanded watcher event handling to also process:
fsnotify.Create
fsnotify.Rename
fsnotify.Remove
Re-register the watcher when a watched file is replaced during an atomic save.
Added existence checks before re-adding the watch to avoid issues when files are actually deleted.
Prevent imports from triggering on permanent file removal.
Reproduction
Before this change: Run: microcks import --watch spec.yaml
Edit and save spec.yaml in VS Code
First save triggers import correctly
Second save is ignored because the watch is no longer active. After this change, repeated saves continue triggering imports correctly.
Testing manually with VsCode and multiple consecutive saves continue triggering imports, watcher recovers after atomic rename operations, also no panic occurs on deletion of file.
Related issue(s) #432