Add support for Rename and Create events in inotify file watching#216
Open
JustinVenus wants to merge 1 commit intoaptible:mainfrom
Open
Add support for Rename and Create events in inotify file watching#216JustinVenus wants to merge 1 commit intoaptible:mainfrom
JustinVenus wants to merge 1 commit intoaptible:mainfrom
Conversation
Fixes aptible#204 Previously, the inotify watcher only handled Write and Remove events. This caused issues when editors like vim perform atomic writes (which generate Rename events) or when files are atomically swapped via directory operations. This change: - Adds explicit handling for Rename events by re-adding the watch after rename operations (ensuring continued monitoring when files are replaced) - Adds handling for Create events (which occur with atomic writes from some editors) - Improves error handling for Remove events to be non-fatal (important for Kubernetes configmap/secret mounts) - Maintains watching the specific file path rather than the directory or inode, as preferred by users The solution watches the file path and handles all event types that can occur during atomic file operations, making it robust for both editor-based edits and atomic swap scenarios without requiring directory-level watching.
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.
Summary
This PR adds support for
RenameandCreateevents in the inotify file watching implementation, fixing issue #204.Problem
The current inotify implementation only handles
WriteandRemoveevents. This causes two main issues:Editor atomic writes: Editors like vim perform atomic writes by creating a temporary file and then renaming it over the original. This generates
Renameevents that were previously ignored, causing supercronic to miss file changes.Atomic file swaps: Users who want to atomically swap entire crontab configurations (e.g., by preparing a new directory and swapping it) cannot rely on supercronic detecting the new file at the watched path, as the swap operation generates
Renameevents.Solution
This implementation:
Handles
Renameevents: When a rename is detected, the watch is re-added to the file path to ensure continued monitoring. This is critical because after a rename, the file descriptor may point to a different inode, but we want to continue watching the same path.Handles
Createevents: Many editors use atomic writes that generateCreateevents. By handling these explicitly, we ensure all editor-based modifications are detected.Improves
Removeevent handling: Makes error handling non-fatal for remove events (important for Kubernetes configmap/secret mounts where temporary removals are expected).Maintains path-based watching: Unlike alternative solutions that would require watching entire directories, this solution continues to watch the specific file path, which is the preferred behavior according to the issue discussion.
Why This Solution?
This approach is preferred over alternatives because:
Path-based watching: Users want to watch a specific path (preferably inside a directory) rather than an inode or entire directory. This solution maintains that behavior.
Comprehensive event handling: By handling all relevant filesystem events (
Write,Create,Rename,Remove), we cover all possible atomic write patterns used by editors and file management systems.Minimal changes: This solution extends the existing event handling logic without requiring architectural changes or additional dependencies (like
fswatch).Kubernetes compatibility: The improved error handling ensures the solution works reliably with Kubernetes configmap and secret mounts, which use atomic write patterns.
Testing
The existing integration tests in
integration/reload.batsalready cover:This change extends that coverage to also handle:
Related Issues