Skip to main content

link_edge_key

Function link_edge_key 

Source
pub fn link_edge_key(canonical_target: &str) -> String
Expand description

The comparison key for a canonical link target. Two normalizations, applied in order, so the string-keyed edge comparison agrees with how the filesystem resolves the same link:

  1. Unicode NFC, always. macOS/APFS folds NFC and NFD forms of a name to the same file, so a file records/contacts/josé.md written NFC (é = U+00E9) and a link [[records/contacts/josé]] written NFD (e + U+0301) name the same file on disk — yet their raw UTF-8 bytes differ. Without normalization the graph keys them as two different targets, so backlinks/forwardlinks miss the edge and orphans flags a linked-to file as an orphan, while validate (which resolves through the filesystem) sees the link as live: the surfaces silently disagree. Normalizing BOTH sides to NFC here makes the comparison normalization-insensitive, matching the filesystem. This lives in the comparison key — not in canonical_link_target — so the canonical form stays byte/normalization-preserving (rename REWRITE output is never silently re-normalized); both the link target and the file path pass through this function, so NFC here is sufficient to unify them.
  2. ASCII case-fold on a case-insensitive filesystem. Identity on a case-sensitive FS, ASCII-lowercased on macOS/Windows, so the comparison also agrees with the filesystem’s case-folding is_file() resolution.

Callers compare link_edge_key(a) == link_edge_key(b).