Skip to content

Fix watcher stopping after atomic file saves#433

Open
PranjaliBhardwaj wants to merge 1 commit into
microcks:masterfrom
PranjaliBhardwaj:newb
Open

Fix watcher stopping after atomic file saves#433
PranjaliBhardwaj wants to merge 1 commit into
microcks:masterfrom
PranjaliBhardwaj:newb

Conversation

@PranjaliBhardwaj
Copy link
Copy Markdown
Contributor

@PranjaliBhardwaj PranjaliBhardwaj commented May 24, 2026

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

Signed-off-by: Pranjali Bhardwaj <pranjalisharma6543@gmail.com>
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

Successfully merging this pull request may close these issues.

1 participant