Skip to content

Add a file watcher in the daemon to detect stale blobs #3

Description

@rikettsie

Context

Blobs are imported using ImportMode::TryReference, which means the FsStore keeps a reference to the original file path on disk rather than copying it. If that file is deleted after import, the reference becomes dnagling/stale: peers requesting the blob receive an error. The failure is silent until a peer actually attempts the transfer.

Goal

Add a background file watcher in the daemon that monitors every path referenced by a blob hash and emits a warning log when a referenced file disappears or is moved.

Acceptance criteria

  • On daemon startup, the watcher registers all paths currently referenced by known blobs (enumerated via Node::list_blobs);
  • When a new blob is imported via Op::Import, its source path is registered with the watcher;
  • When a watched path is deleted or renamed, the daemon logs a structured warn! entry that includes the blob hash and the affected path;
  • When a blob is explicitly removed via Op::BlobRemove, its path is deregistered from the watcher;
  • The watcher runs as a non-blocking background task inside the daemon; connection handling is not impacted (!);
  • Path watching works on Linux (via inotify), macOS (via FSEvents / kqueue), and Windows (via ReadDirectoryChangesW). Use the notify crate to abstract over all three;
  • If registering a watch on a path fails (e.g. the path has already been moved at startup, or permission is denied), the daemon logs a warn! rather than panicking at start;
  • Directory imports: each contained file path discovered during the walk is individually registered with the watcher to support a granular sensing.

Out of scope

  • Automatically removing or invalidating the blob from the store when a file disappears;
  • Re-importing the blob if the original file reappears;
  • Detecting hash content mismatch after an in-place file modification;
  • Watching paths on network or remote filesystems;
  • Sending integrity events to connected daemon clients over the IPC protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement of existing function/behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions