Expand description
Filesystem state sync engine (docs/fs-watch.md).
The server side of FEATURE_FS, split in two:
- A shared root per watched
(path, recursive, cross_filesystem), refcounted across every sync of that root on every connection: one native watcher, one hint-driven reconciler owning the canonical metadata index, publishing immutableArc<Index>snapshots. - A per-sync engine holding only client state: the shadow snapshot
(what the client holds), the held-content map for delta bases, the
ack window, and staged
RESET … SYNCupdate assembly.
Content flows through the process-wide content-addressed blob store: once any sync reads and hashes a file, the reconciler adopts the hash and every other sync serves those bytes from memory. Native backends deliver hints (a path may have changed / rescan everything); all protocol-visible behavior lives here, so the three platforms behave identically by construction.
Re-exports§
pub use ignores::IgnoreSpec;pub use ignores::MAX_PATTERNS as MAX_IGNORE_PATTERNS;
Modules§
- backend
- Native watch backend via the
notifycrate (inotify on Linux, FSEvents on macOS,ReadDirectoryChangesWon Windows), demoted to a dirty-set hint source: every event becomesHint::Dirty(path)and every loss signal — overflow, rescan flag, backend error — degrades toHint::Rescan. No backend behavior is client-visible; the engine verifies everything against the filesystem before emitting. - ignores
- Configurable exclusion for a synced root (docs/design/fs-watch.md “Ignoring”).
Structs§
- Blob
Store - Content-addressed LRU cache of file bytes, keyed by BLAKE3-128 and shared by every sync in the process: identical files cost one entry, and delta bases are found by the hash each engine recorded for the content its client holds. Eviction only costs efficiency — a missing base falls back to full content.
- Hint
Sender - Wrap the reconciler inbox for a hint source (native backend or test).
- Inflight
Guard - Per-connection in-flight write accounting. The server inserts a
request’s nonce before dispatch — rejecting a duplicate (
INVALID) or an over-cap request (BUDGET) — and attaches this guard to the request; the engine drops it once the request is answered, removing the nonce and freeing a slot. Bounds the otherwise-unbounded engine channel depth (and thus resident inbound content) to the in-flight cap. - Node
Meta - Noop
Backend - OpReq
- A metadata op forwarded to the engine.
opisFS_OP_*;a/bare escaped wire paths (bempty except forRENAME). - RootKey
- Identity of a shared root. Enumeration scope is part of the identity: recursive and non-recursive syncs of the same directory index different trees and cannot share a reconciler — and neither do two syncs that exclude different things, for exactly the same reason.
- Shared
Root Handle - A shared root: keeps the native watcher armed and the reconciler
reachable. Engines hold an
Arc; when the last one drops, the watcher disarms, the reconciler’s inbox disconnects, and its thread exits. - Sync
Handle - Handle owned by the client connection. Dropping it stops the engine (and, transitively, releases its share of the root).
- Sync
Options - Write
Req - A content write forwarded to the engine (docs/design/fs-write.md).
pathis the escaped wire path;flagsareFS_WRITE_*.
Enums§
- Command
- Commands forwarded from the client connection.
- DiffOp
- Hint
- A hint from a native backend. Hints are unreliable and duplicated; the reconciler verifies everything against the filesystem before emitting.
- Read
Outcome
Traits§
- Backend
Handle - Registration interface a backend exposes to the reconciler so the set of watched directories tracks the set of indexed ones (inotify, where a recursive watch is a descriptor per directory and an excluded subtree would otherwise still cost them all). FSEvents/RDCW cover a tree with one object and use the no-op default, as does any unfiltered root.
Functions§
- blake3_
128 - BLAKE3 truncated to 128 bits, little-endian — the protocol-wide content
hash (docs/design/fs-watch.md).
pubso sibling stores (the KV store, docs/design/kv.md) share the one convention instead of re-deriving it. - blob_
store - The process-wide store; budget via
BLIT_FS_BLOB_MAX(default 256 MiB). - diff
- Compute ops that transform
previntocurr. - encode_
delta - Single-span delta: the longest common prefix and suffix become
COPYs, the middle anINSERT. Covers appends, prepends, truncations, and one contiguous in-place edit — the common shapes of saved files and logs. Scattered edits degrade to a largeINSERT; the caller falls back to full content when the encoding is not clearly smaller. - escape_
bytes - escape_
path - Escape a whole path for wire use (e.g. the
FS_SYNCEDcanonical-root detail): same scheme as components, separators left intact. - escape_
wide - Escape UTF-16 code units (Windows names): valid text passes through
(
%→%25), unpaired surrogates become%uXXXX. A literal%uin a name escapes to%25u, so the forms never collide. Pure so every host can test it;cfg(windows)wires it toOsStr. - open_
root - Open (or join) the shared root for
key, arming a native watcher on first open — before the initial enumeration, so nothing slips between scan and event delivery. On failure returns anFS_STATUS_*code plus diagnostic, so the server can answerFS_SYNCEDaccurately. - open_
root_ unwatched - Open (or join) a shared root without a native watcher; hints come from
SharedRootHandle::hint_sender. For tests and embedders. - open_
single_ root - Open (or join) the shared root for an
FS_SYNC_SINGLEsync ofpath(a canonical FILE path fromvalidate_single_root). The native watch arms on the file’s PARENT directory, non-recursive — a watch on the file itself would follow its inode and go silent after a delete or a rename-over, exactly the transitions a single-file sync must deliver.recursive/cross_filesystem/ignoresdo not apply (nothing is enumerated — the client named the one file it wants), so every SINGLE sync of one file shares a single normalized key. - open_
single_ root_ unwatched open_single_rootwithout a native watcher; hints come fromSharedRootHandle::hint_sender. For tests and embedders.- read_
verified - [
read_verified_meta] without the stat, for fetch responses and tests. - resolve_
wire_ path - Resolve a wire path (relative, ‘/’-separated, escaped) against a root. Rejects traversal — the result always stays under the root.
- start_
sync - Spawn a sync engine subscribed to
shared, streaming tooutbox. The engine’s initialRESET … SYNCseries is cut from the root’s current snapshot — later syncs of an already-watched root never rescan. - unescape_
to_ bytes - Reverse
escape_bytes. ReturnsNoneon malformed escapes. - unescape_
to_ wide - Reverse
escape_wide:%uXXXX→ one code unit,%XX→ one unit below 0x100 (covers%25), everything else re-encoded as UTF-16. - validate_
root - Validate and canonicalize a requested root. Returns the canonical path
or an
FS_STATUS_*code plus diagnostic. - validate_
single_ root - Validate and canonicalize an
FS_SYNC_SINGLEroot: the same canonicalization asvalidate_root, plus the path must not be a directory — a directory root answers the existing invalid-path error (docs/design/fs-watch.md “Single-file sync”). Canonicalization resolves symlinks, so the returned path is the file itself, never a link to it.
Type Aliases§
- Outbox
- Messages the engine emits, ready for the client outbox. Returns
falsewhen the client is gone; the engine then exits.