Source code for cadrumo.adapters.outbound.storage.path_budget
"""Worst-case on-disk object-path length for the local provider layout.This package owns the ``local_provider_object_sidecar`` grammar(``<root>/buckets/<bucket_id>/blobs/<namespace>/<hmac_prefix>--<label>.meta.json``,declared with ``owner="cadrumo.adapters.outbound.storage"`` in:data:`~adapters.persistence.storage.namespace_registry.STORAGE_NAMESPACE_REGISTRY`), so thedeepest suffix that grammar can produce is derived here and handed to:func:`~core.paths.windows_storage_root_long_path_margin` rather thanduplicated as a literal beneath it.The ``<namespace>`` segment is the load-bearing one, and it was previouslymis-sourced. ``LocalFileSystemProvider`` fans one directory out per namespace(``self._root / namespace``), and the namespaces it is handed in productionare *registered secure-object namespaces*: the mirror push loop passes``SecureObjectRawRow.namespace`` straight to:meth:`~adapters.outbound.storage.protocol.StorageProvider.put`, and the mirrorpreflight refuses any namespace absent from the registry. Those values aredotted and long (the longest shipped is 72 characters). The prior constantinstead spelled a bucket-event object type into the arithmetic — a disjointvocabulary whose values are never registered storage namespaces at all — andso understated the worst case by 54 characters, which could let the preflightmargin accept a storage root from which a real outbound write then exceeds``MAX_PATH``.Deriving from :data:`~adapters.persistence.storage.namespace_registry.STORAGE_NAMESPACE_REGISTRY`makes the ceiling structural over the whole shipped domain: a newly registerednamespace longer than today's longest raises the budget automatically insteadof silently re-opening the gap.The registry field caps ``namespace`` at 128 characters, which is the onlyhard structural bound available. Budgeting against that cap rather than theshipped maximum would put the suffix alone at 265 characters — past:data:`~core.paths.WINDOWS_MAX_PATH` (260) before any root is prepended — soevery margin would be negative and the preflight probe would refuse everystorage root on every Windows workstation. The shipped-longest derivation isthe honest budget: it measures the deepest path this build can actually write."""from__future__importannotationsfromfunctoolsimportlru_cache__all__=["windows_worst_case_object_path_suffix_length"]#: Canonical UUIDv4 string length, the ``<bucket_id>`` segment's fixed width._BUCKET_ID_LENGTH=36#: Windows path separator. The suffix is measured in the worst-case (longest)#: spelling; POSIX separators are the same width, so the count is portable._SEPARATOR="\\"
[docs]@lru_cache(maxsize=1)defwindows_worst_case_object_path_suffix_length()->int:"""Return the longest object-path suffix this build's layout can append. Measured from the leading separator through the sidecar extension, using the real grammar constants: the bucket/blob directory names, a 36-character bucket id, the longest namespace registered in :data:`~adapters.persistence.storage.namespace_registry.STORAGE_NAMESPACE_REGISTRY`, the HMAC prefix width, and the operator-label cap. The ``.meta.json`` sidecar is measured rather than the ``.bin`` payload because it is the longer of the two names the provider writes for one object, so a path that fits the sidecar fits the payload. Returns: The suffix length in characters, for :func:`~core.paths.windows_storage_root_long_path_margin`. """from...persistence.storage.namespace_registryimportSTORAGE_NAMESPACE_REGISTRYfrom...persistence.storage.storage_path_definitionsimportBUCKET_BLOBS_DIRNAME,BUCKETS_DIRNAMEfrom._object_nameimportHMAC_PREFIX_LENGTH,LABEL_MAX_LENGTHfrom.localimportSIDECAR_EXTENSIONlongest_namespace=max(len(definition.namespace)fordefinitioninSTORAGE_NAMESPACE_REGISTRY.namespaces)returnlen(_SEPARATOR+BUCKETS_DIRNAME+_SEPARATOR+("0"*_BUCKET_ID_LENGTH)+_SEPARATOR+BUCKET_BLOBS_DIRNAME+_SEPARATOR+("n"*longest_namespace)+_SEPARATOR+("a"*HMAC_PREFIX_LENGTH)+"--"+("b"*LABEL_MAX_LENGTH)+SIDECAR_EXTENSION,)