aeat.adapters.persistence.storage.bucket._manifest_io module

Atomic read/write IO for the plaintext bucket manifest.

The manifest sits at <bucket-dir>/manifest.toml. Writes use the write-then-rename pattern (tmp sibling, os.replace) so a crash mid-write can never surface as a torn read; reads round-trip through the strict pydantic v2 BucketManifest record so an unknown key or a torn payload fails closed at the boundary.

manifest_path(paths)[source]

Return the canonical manifest path for the bucket.

Return type:

Path

Parameters:

paths (BucketPaths)

manifest_validation_error(message)[source]

Build the typed, localized StorageValidationError used by manifest I/O.

Return type:

StorageValidationError

Parameters:

message (str)

write_manifest(paths, manifest)[source]

Atomically write the manifest under <bucket-dir>/manifest.toml.

Uses a write-then-rename pattern: the payload is staged under a .tmp sibling, fsync-ed, and renamed in place via os.replace(), after which the parent directory is fsync-ed too. A crash mid-write leaves either the previous good manifest or the new good manifest, never a torn intermediate; the fsync pair makes that guarantee survive a hard power loss (matching the rotation atomic-write path), so a half-flushed tmp file can no longer become a zero-length manifest on reboot.

Return type:

None

Parameters:
read_manifest(paths)[source]

Read and strict-validate the manifest from <bucket-dir>/manifest.toml.

Parameters:

paths (BucketPaths) – The resolved bucket paths providing the manifest file location.

Return type:

BucketManifest

Returns:

A strict-validated BucketManifest.

Raises:

StorageValidationError – When the manifest cannot be read, cannot be parsed, or is missing the lifecycle status key.