persist: rename write map to attribute map

This commit is contained in:
Johannes Kirschbauer
2025-10-10 10:09:34 +02:00
parent f57bc30c5a
commit c13879ce69
4 changed files with 19 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ from clan_lib.persist.path_utils import (
path_match,
set_value_by_path_tuple,
)
from clan_lib.persist.write_rules import WriteMap, compute_write_map
from clan_lib.persist.write_rules import AttributeMap, compute_write_map
def unwrap_known_unknown(value: Any) -> Any:
@@ -79,7 +79,7 @@ def sanitize(data: Any, whitelist_paths: list[str], current_path: list[str]) ->
@dataclass
class WriteInfo:
writeables: WriteMap
writeables: AttributeMap
data_eval: "InventorySnapshot"
data_disk: "InventorySnapshot"

View File

@@ -15,7 +15,7 @@ from clan_lib.persist.validate import (
validate_type_compatibility,
validate_writeability,
)
from clan_lib.persist.write_rules import WriteMap
from clan_lib.persist.write_rules import AttributeMap
def find_deleted_paths_structured(
@@ -88,7 +88,7 @@ def calc_patches(
persisted: dict[str, Any],
update: dict[str, Any],
all_values: dict[str, Any],
writeables: WriteMap,
writeables: AttributeMap,
) -> tuple[dict[PathTuple, Any], set[PathTuple]]:
"""Calculate the patches to apply to the inventory using structured paths.

View File

@@ -7,7 +7,7 @@ from clan_lib.persist.path_utils import (
path_starts_with,
path_to_string,
)
from clan_lib.persist.write_rules import WriteMap, is_writeable_path
from clan_lib.persist.write_rules import AttributeMap, is_writeable_path
def validate_no_static_deletion(
@@ -29,7 +29,7 @@ def validate_no_static_deletion(
raise ClanError(msg)
def validate_writeability(path: PathTuple, writeables: WriteMap) -> None:
def validate_writeability(path: PathTuple, writeables: AttributeMap) -> None:
"""Validate that a path is writeable."""
if not is_writeable_path(path, writeables):
msg = f"Path '{path_to_string(path)}' is readonly. - It seems its value is statically defined in nix."

View File

@@ -1,3 +1,4 @@
from enum import Enum
from typing import Any, TypedDict
from clan_lib.errors import ClanError
@@ -6,14 +7,19 @@ from clan_lib.persist.path_utils import PathTuple, path_to_string
WRITABLE_PRIORITY_THRESHOLD = 100 # Values below this are not writeable
class WriteMap(TypedDict):
class PersistenceAttribute(Enum):
READONLY = "readonly"
class AttributeMap(TypedDict):
writeable: set[PathTuple]
non_writeable: set[PathTuple]
attrs: dict[PathTuple, set[PersistenceAttribute]]
def is_writeable_path(
key: PathTuple,
writeables: WriteMap,
writeables: AttributeMap,
) -> bool:
"""Recursively check if a key is writeable.
@@ -35,7 +41,7 @@ def is_writeable_path(
def is_writeable_key(
key: str,
writeables: WriteMap,
writeables: AttributeMap,
) -> bool:
"""Recursively check if a key is writeable.
@@ -101,14 +107,14 @@ def _determine_writeability_recursive(
current_path: PathTuple = (),
inherited_priority: int | None = None,
parent_redonly: bool = False,
results: WriteMap | None = None,
) -> WriteMap:
results: AttributeMap | None = None,
) -> AttributeMap:
"""Recursively determine writeability for all paths in the priority structure.
This is internal recursive function. Use 'determine_writeability' as entry point.
"""
if results is None:
results = WriteMap(writeable=set(), non_writeable=set())
results = AttributeMap(writeable=set(), non_writeable=set(), attrs={})
for key, value in priorities.items():
# Skip metadata keys
@@ -172,7 +178,7 @@ def _determine_writeability_recursive(
def compute_write_map(
priorities: dict[str, Any], all_values: dict[str, Any], persisted: dict[str, Any]
) -> WriteMap:
) -> AttributeMap:
"""Determine writeability for all paths based on priorities and current data.
- Priority-based writeability: Values with priority < 100 are not writeable