Skip to content

Commit

Permalink
fix: use event.Has func for file change notification handling (increa…
Browse files Browse the repository at this point in the history
…sed stability across OS) (#361)

<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR

- Uses event.Has func for file change notification handling (instead of
direct comparison). This is the correct approach as [expressed directly
in fsnotify's
code](https://github.com/fsnotify/fsnotify/blob/main/fsnotify.go#L39).

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

Fixes #313 

### Notes
<!-- any additional notes for this PR -->

### Follow-up Tasks
<!-- anything that is related to this PR but not done here should be
noted under this section -->
<!-- if there is a need for a new issue, please link it here -->

### How to test
<!-- if applicable, add testing instructions under this section -->

---------

Signed-off-by: Skye Gill <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Todd Baert <[email protected]>
  • Loading branch information
skyerus and toddbaert authored Feb 1, 2023
1 parent 4f1905a commit 09f74b9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/sync/file/filepath_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ func (fs *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {

fs.Logger.Info(fmt.Sprintf("filepath event: %s %s", event.Name, event.Op.String()))

switch event.Op {
case fsnotify.Create, fsnotify.Write:
// event.Op is a bitmask and some systems may send multiple operations at once
// event.Has(...) checks that the bitmask contains the particular event (among others)
if event.Has(fsnotify.Create) || event.Has(fsnotify.Write) {
fs.sendDataSync(ctx, event, dataSync)
case fsnotify.Remove:
} else if event.Has(fsnotify.Remove) {
// Counterintuively, remove events are the only meanful ones seen in K8s.
// K8s handles mounted ConfigMap updates by modifying symbolic links, which is an atomic operation.
// At the point the remove event is fired, we have our new data, so we can send it down the channel.
fs.sendDataSync(ctx, event, dataSync)

Expand Down

0 comments on commit 09f74b9

Please sign in to comment.