cadrumo.adapters.persistence.storage.custody.filesystem module

Identity-anchored local filesystem substrate for profile custody.

profile_custody_local_lock(path, *, timeout_seconds=30.0)[source]

Hold a no-follow, parent-anchored cross-process custody lock.

On POSIX the descriptor is opened relative to a pinned parent and locked with flock. Windows opens the exact no-reparse leaf with no sharing; the kernel releases that exclusion when a process dies. Neither platform relies on a stale lock-file convention.

Return type:

Generator[None]

Parameters:
profile_custody_root_lock(root, *, timeout_seconds=30.0)[source]

Hold the single re-entrant root lock for every current custody pointer mutation.

This is deliberately a separate primitive from leaf locks: both the application active-pointer transaction and custody compare-and-swap use this exact root lock identity. Re-entry is limited to the same process, thread, and effective root; sibling processes retain kernel-enforced exclusion through profile_custody_local_lock().

Return type:

Generator[None]

Parameters:
read_profile_custody_local_record(path, *, maximum_bytes)[source]

Read an auxiliary local custody record through the same anchored no-follow primitive.

Return type:

bytes

Parameters:
read_optional_profile_custody_local_record(path, *, maximum_bytes)[source]

Read a local record or prove its absence through the anchored primitive.

Callers that need an absent-vs-corrupt distinction must not first inspect a pathname and then reopen it. This keeps that distinction inside the same no-follow, identity-anchored operation as the bounded read.

Return type:

bytes | None

Parameters:
write_profile_custody_local_record(path, payload, *, publish_once)[source]

Durably write an auxiliary local custody record under pinned ancestry.

publish_once uses a no-replace publication; mutable journals are first read through the paired no-follow primitive and then atomically replaced.

Return type:

None

Parameters:
compare_and_replace_profile_custody_local_record(path, *, expected, replacement, maximum_bytes)[source]

Atomically replace a local custody record through the transition engine.

Return type:

None

Parameters:
compare_and_replace_same_or_predecessor_profile_custody_local_record(path, *, current, predecessor, maximum_bytes)[source]

Publish a current custody record only from its exact predecessor.

Return type:

None

Parameters:
compare_and_clear_profile_custody_local_record(path, *, expected, maximum_bytes)[source]

Remove a local custody record only when its anchored bytes still match.

Return type:

None

Parameters:
clear_profile_custody_local_record(path)[source]

Remove one local record through an anchored verified leaf handle.

The operation opens and verifies the leaf before any unlink/delete action; it never performs a lexists/unlink path sequence. The caller’s custody root lock serializes cooperating writers, while the pinned parent and non-delete-shared Windows handle prevent ancestry or leaf substitution during this operation.

Return type:

None

Parameters:

path (Path)

lexists(path, *, trace)
Return type:

bool

Parameters:
posix_child_exists(parent_fd, name, *, trace, display_path)
Return type:

bool

Parameters:
read_regular_file(path, *, maximum_bytes, trace=None, missing_ok=False)
Return type:

bytes | None

Parameters:
read_regular_file_fd(parent_fd, name, *, display_path, maximum_bytes, trace)
Return type:

bytes

Parameters:
read_regular_file_open(path, *, maximum_bytes, trace, parent_fd=None, missing_ok=False)
Return type:

bytes | None

Parameters:
windows_regular_file_anchor(path, *, missing_ok=False)

Reject a final reparse point, then lock the verified leaf against replacement.

Parameters:
posix_open_exclusive_file(parent_fd, name)
Return type:

int

Parameters:
write_descriptor_fsynced(descriptor, payload)
Return type:

None

Parameters:
write_windows_local_stage(path, payload)
Return type:

None

Parameters:
windows_replace_file(*, target, replacement, backup)

Replace one custody record through ReplaceFileW.

The sys.platform == "win32" block, rather than a guard at the call site or an early return, is what establishes the platform for the Windows API below: it is the only guard shape every checker this project runs narrows on, so those references resolve when the tree is analysed for a platform that does not ship them.

Return type:

None

Parameters:
windows_read_handle_bounded(*, handle, info, maximum_bytes)

Read a bounded record from an already-verified Windows handle.

The sys.platform == "win32" block, rather than a guard at the call site or an early return, is what establishes the platform for the Windows API below: it is the only guard shape every checker this project runs narrows on, so those references resolve when the tree is analysed for a platform that does not ship them.

Return type:

bytes

Parameters:
  • handle (int)

  • info (Any)

  • maximum_bytes (int)

renameat2_exchange(*, parent_fd, first_name, second_name)

Swap two named children atomically below the same pinned POSIX parent.

Return type:

None

Parameters:
  • parent_fd (int)

  • first_name (str)

  • second_name (str)