Repository navigation
Description
Context
After the 2026-04-20 path-consolidation work (lib-audit L5),
MediaPath::new no longer NFC-normalizes its input. Production
MediaPaths are built downstream of fs::canonicalize. The
per-platform filesystem semantics:
- macOS HFS+: stores NFD; realpath returns NFD.
- macOS APFS: stores caller-form-preserving; dirent lookup
uses hash-of-normalized (per Apple APFS FAQ); realpath returns
the stored dirent name (whichever form the file was written
under). - NTFS (Windows): Win32 layer applies normalization; storage
is UTF-16 as given. Behavior across NT versions is complex. - ext4 (Linux): byte-exact — no Unicode equivalence.
The macOS user impact
A user with an existing perima DB populated pre-L5 has
NFC-normalized relative_path bytes in file_locations. On a
macOS HFS+ machine, a fresh scan post-L5 produces NFD bytes. The
DB ends up with two file_locations rows for the same physical
file: one NFC (pre-L5), one NFD (post-L5). APFS defaults since
macOS 10.13 (2017), so HFS+ impact is narrow — but possible for
any early adopter who migrated from HFS+ to APFS while retaining
the original dirent forms.
FTS5 secondary impact
crates/db/src/search_repo.rs indexes relative_path into FTS5
for filename tokenization. With duplicate rows in file_locations,
the FTS5 content has BOTH NFC + NFD tokenized. macOS users typing
NFC queries (macOS keyboard default) hit only the pre-L5 row; the
NFD rows become effectively unsearchable via NFC queries. The
migration below MUST rebuild the FTS5 content after collapsing
duplicates — simply deleting duplicate file_locations rows
without refreshing FTS5 leaves stale tokens.
Acceptance criteria
- Detect duplicate-by-hash
file_locationsrows whose
relative_pathdiffers only by Unicode normalization form. - Canonicalize the absolute path via
fs::canonicalize; rewrite
the winning row'srelative_pathto match the canonicalized
form; soft-delete the losing row (per CRDT-ready soft-delete
discipline). - Rebuild the FTS5 virtual-table content (
INSERT INTO fts5(fts5) VALUES('rebuild')) OR surgically delete-and-re-insert affected
rows. - Ship the migration as part of Phase 9 hardening — DB versioning
handles multi-step migrations; add the step to the migration
pipeline.
Labels
phase-9-hardening — hardening + cert procurement phase.
library-audit-followup — L5 work surfaced this.
Activity