Collision-resistant wiki name for a synthetic identity ``path_key``. Same rules as :func:`resolve_doc_name` minus the legacy-by-stem backfill (a filesystem-migration concern that must not fire for sources with no real path, e.g. cloud imports). A source already registered under ``pa
(stem: str, path_key: str, registry: HashRegistry)
| 111 | |
| 112 | |
| 113 | def resolve_doc_name_from_key(stem: str, path_key: str, registry: HashRegistry) -> str: |
| 114 | """Collision-resistant wiki name for a synthetic identity ``path_key``. |
| 115 | |
| 116 | Same rules as :func:`resolve_doc_name` minus the legacy-by-stem |
| 117 | backfill (a filesystem-migration concern that must not fire for sources |
| 118 | with no real path, e.g. cloud imports). A source already registered |
| 119 | under ``path_key`` keeps its stored ``doc_name``; otherwise the |
| 120 | sanitized ``stem`` is used, with a deterministic |
| 121 | ``-{sha256(path_key)[:8]}`` suffix when another document owns it. |
| 122 | """ |
| 123 | known = registry.get_by_path(path_key) |
| 124 | if known is not None: |
| 125 | stored = known.get("doc_name") or Path(known.get("name", "")).stem |
| 126 | if stored: |
| 127 | return stored |
| 128 | |
| 129 | candidate = _sanitize_stem(stem) |
| 130 | if _name_taken(candidate, registry): |
| 131 | digest = hashlib.sha256(path_key.encode("utf-8")).hexdigest()[:_SUFFIX_LEN] |
| 132 | return f"{candidate}-{digest}" |
| 133 | return candidate |
| 134 | |
| 135 | |
| 136 | def get_pdf_page_count(path: Path) -> int: |