Rewrite
rewrite
Pure classification of a whole-file rewrite target.
The predicate below is the SINGLE source of truth shared by
batch_edit_check (dry-run diagnostics) and batch_edit (apply path), so
the two tools can never drift apart on what a valid rewrite target is. It is
pure by construction: it takes already-observed facts (booleans and digests),
never a Path, and touches no filesystem.
Diagnostic codes, evaluated in this fixed order:
rewrite_target_missing— the target does not exist.rewrite_target_not_regular— the target exists but is not a regular file (symlink, directory, device, ...).rewrite_checksum_stale— the target is a regular file but its digest no longer matches the one the caller read.
None means the target is valid for a rewrite.
classify_rewrite_target(*, exists, is_regular, actual_checksum, expected_checksum)
Classify an observed rewrite target against its expected digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exists
|
bool
|
Whether the target path exists. |
required |
is_regular
|
bool
|
Whether the target is a regular file (not a symlink, directory or other special file). |
required |
actual_checksum
|
str | None
|
Digest of the bytes currently on disk, or |
required |
expected_checksum
|
str
|
Digest the caller read before proposing the rewrite. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
|
str | None
|
diagnostic code in the documented order. |
Source code in packages/axm-edit/src/axm_edit/core/rewrite.py
compute_checksum(data)
Return the lowercase 64-char sha256 hex digest of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The exact bytes to digest (no decoding, no normalisation). |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in packages/axm-edit/src/axm_edit/core/rewrite.py
| Python | |
|---|---|