Find a pre-path-index entry matching ``stem``. Returns ``(file_hash, metadata)`` for an entry that has no truthy ``path`` (a missing or empty ``path`` is treated as unindexed) and whose ``doc_name`` — or, for even older entries lacking ``doc_name``, the stem of its `
(self, stem: str)
| 53 | return None |
| 54 | |
| 55 | def find_legacy_by_stem(self, stem: str) -> tuple[str, dict] | None: |
| 56 | """Find a pre-path-index entry matching ``stem``. |
| 57 | |
| 58 | Returns ``(file_hash, metadata)`` for an entry that has no truthy |
| 59 | ``path`` (a missing or empty ``path`` is treated as unindexed) and |
| 60 | whose ``doc_name`` — or, for even older entries lacking |
| 61 | ``doc_name``, the stem of its ``name`` — equals ``stem``. When |
| 62 | several legacy entries match (pre-fix registries can hold |
| 63 | same-named entries), the first in insertion order is returned. |
| 64 | Callers use the hash to backfill ``path`` via :meth:`add`. Returns |
| 65 | None when every matching name is already path-indexed. The |
| 66 | comparison is NFKC-normalized on both sides, so macOS NFD |
| 67 | filenames match their NFC registry entries. |
| 68 | """ |
| 69 | for file_hash, metadata in self._data.items(): |
| 70 | if metadata.get("path"): |
| 71 | continue |
| 72 | entry_name = metadata.get("doc_name") or Path(metadata.get("name", "")).stem |
| 73 | if unicodedata.normalize("NFKC", entry_name) == unicodedata.normalize("NFKC", stem): |
| 74 | return file_hash, metadata |
| 75 | return None |
| 76 | |
| 77 | # ------------------------------------------------------------------ |
| 78 | # Mutation |