Skip to content

feat(agent/agentcontainers): add file watcher and dirty status #17573

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

Merged
merged 23 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
s/ErrWatcherClosed/ErrClosed/g
  • Loading branch information
mafredri committed Apr 28, 2025
commit 0b16448052173f8a890bec005578ea1c8a3e018b
2 changes: 1 addition & 1 deletion agent/agentcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (api *API) start() {
for {
event, err := api.watcher.Next(api.ctx)
if err != nil {
if errors.Is(err, watcher.ErrWatcherClosed) {
if errors.Is(err, watcher.ErrClosed) {
api.logger.Debug(api.ctx, "watcher closed")
return
}
Expand Down
4 changes: 2 additions & 2 deletions agent/agentcontainers/watcher/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ func (n *noopWatcher) Next(ctx context.Context) (*fsnotify.Event, error) {
case <-ctx.Done():
return nil, ctx.Err()
case <-n.done:
return nil, ErrWatcherClosed
return nil, ErrClosed
}
}

func (n *noopWatcher) Close() error {
n.mu.Lock()
defer n.mu.Unlock()
if n.closed {
return ErrWatcherClosed
return ErrClosed
}
n.closed = true
close(n.done)
Expand Down
10 changes: 5 additions & 5 deletions agent/agentcontainers/watcher/watcher.go
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this package could be moved outside of agentcontainers for later re-use, but that doesn't have to be done in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a valid suggestion, but I'd like to defer until the need arises to keep devcontainer related stuff contained (heh).

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"golang.org/x/xerrors"
)

var ErrWatcherClosed = xerrors.New("watcher closed")
var ErrClosed = xerrors.New("watcher closed")

// Watcher defines an interface for monitoring file system changes.
// Implementations track file modifications and provide an event stream
Expand Down Expand Up @@ -140,7 +140,7 @@ func (f *fsnotifyWatcher) Next(ctx context.Context) (event *fsnotify.Event, err
return nil, ctx.Err()
case evt, ok := <-f.Events:
if !ok {
return nil, ErrWatcherClosed
return nil, ErrClosed
}

// Get the absolute path to match against our watched files.
Expand All @@ -160,11 +160,11 @@ func (f *fsnotifyWatcher) Next(ctx context.Context) (event *fsnotify.Event, err

case err, ok := <-f.Errors:
if !ok {
return nil, ErrWatcherClosed
return nil, ErrClosed
}
return nil, xerrors.Errorf("watcher error: %w", err)
case <-f.done:
return nil, ErrWatcherClosed
return nil, ErrClosed
}
}
}
Expand All @@ -178,7 +178,7 @@ func (f *fsnotifyWatcher) Close() (err error) {
f.mu.Unlock()

if closed {
return ErrWatcherClosed
return ErrClosed
}

close(f.done)
Expand Down
Loading