Skip to content

Conversation

realrajaryan
Copy link
Contributor

@realrajaryan realrajaryan commented Sep 17, 2025

Addresses apple/container#141, where containers don't receive filesystem events on mounted volumes, preventing incremental rebuilds and other file-watching features. This PR implements the guest-side components for FSNotify. Host-side implementation in the container repo will complete the pipeline.

Summary:

  • Add gRPC protocol definitions for filesystem event notifications
  • Implement guest-side event handler that generates Linux inotify events
  • Add CLI testing tool (cctl fsnotify) and integration test infrastructure

@realrajaryan realrajaryan force-pushed the users/realrajaryan/fsnotify branch from f89a058 to 128421e Compare September 17, 2025 22:35
@realrajaryan realrajaryan force-pushed the users/realrajaryan/fsnotify branch from 128421e to 816c698 Compare September 17, 2025 23:14
@@ -60,6 +60,8 @@ service SandboxContext {
rpc Sync(SyncRequest) returns (SyncResponse);
// Send a signal to a process via the PID.
rpc Kill(KillRequest) returns (KillResponse);
// Notify guest of filesystem events from host.
rpc NotifyFileSystemEvent(NotifyFileSystemEventRequest) returns (NotifyFileSystemEventResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should have messages for FileSystemEvent and FileSystemEventList, and have the request type deal with lists for performance. We'd need to work out how do deal with errors... perhaps a list of error responses, where each contains a FileSystemEvent, and an error string. An empty response list means no errors.

Choose a reason for hiding this comment

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

or change it to a stream?

Copy link
Member

Choose a reason for hiding this comment

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

A stream is likely the right answer.


// Test 1: CREATE event
print("Testing CREATE event...")
let createResponse = try await agent.notifyFileSystemEvent(path: "/mnt/test/new_file.txt", eventType: .create)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably test create event on an existing file.

The reasoning is that from the point of view of your macOS filesystem monitor it will:

  • Get an event from macOS that a file was created.
  • At this point the file exists and should be accessible to the container (not sure what the latency for this is)
  • Trigger a create event for the already-existing file.

case .modify:
// Touch file to update timestamp -> generates IN_ATTRIB event
let now = Date()
try FileManager.default.setAttributes(
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't change the modification date. The modification date was already changed, we just want to notify.

)

case .create:
// Use chmod with same permissions to generate IN_ATTRIB event
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to error out if we can't get permissions.

chmodding a file from 400 to 644 wouldn't be ideal, nor would changing a file from 755 to 644.

@dcantah
Copy link
Member

dcantah commented Sep 19, 2025

@realrajaryan Can you take a peek at the CI fail, it's for the new test added

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.

4 participants