mirror of
https://github.com/dockur/windows.git
synced 2026-07-28 21:53:34 +07:00
Update iso-prototype.py
This commit is contained in:
+42
-17
@@ -399,40 +399,65 @@ def ensure_parent_directories(iso, logical: PurePosixPath) -> None:
|
||||
iso.add_directory(**namespace_kwargs(iso, current, is_dir=True))
|
||||
|
||||
|
||||
def remove_logical(iso, logical: PurePosixPath) -> bool:
|
||||
found = find_existing_record(iso, logical)
|
||||
if not found:
|
||||
return False
|
||||
|
||||
# rm_file() removes the file and all of its linked namespace records even
|
||||
# when only one valid path is supplied. Passing ISO9660, Joliet, and UDF
|
||||
# paths together is fragile because their spellings need not map exactly
|
||||
# to the same internal record on imported Microsoft media.
|
||||
def remove_found_record(iso, found: dict[str, str]) -> None:
|
||||
# rm_file() removes the inode and all linked namespace records when called
|
||||
# through any one path that actually exists.
|
||||
for namespace in ("udf_path", "joliet_path", "iso_path"):
|
||||
candidate = found.get(namespace)
|
||||
if candidate is None:
|
||||
continue
|
||||
iso.rm_file(**{namespace: candidate})
|
||||
return True
|
||||
return
|
||||
|
||||
return False
|
||||
raise PrototypeError("No usable namespace path was found for removal")
|
||||
|
||||
|
||||
def add_file_all_namespaces(iso, source: Path, logical: PurePosixPath) -> None:
|
||||
ensure_parent_directories(iso, logical)
|
||||
iso.add_file(str(source), **namespace_kwargs(iso, logical))
|
||||
def remove_logical(iso, logical: PurePosixPath) -> bool:
|
||||
found = find_existing_record(iso, logical)
|
||||
if not found:
|
||||
return False
|
||||
remove_found_record(iso, found)
|
||||
return True
|
||||
|
||||
|
||||
def add_file_all_namespaces(
|
||||
iso,
|
||||
source: Path,
|
||||
logical: PurePosixPath,
|
||||
paths: dict[str, str] | None = None,
|
||||
) -> None:
|
||||
if paths is None:
|
||||
ensure_parent_directories(iso, logical)
|
||||
paths = namespace_kwargs(iso, logical)
|
||||
|
||||
if not paths:
|
||||
raise PrototypeError(f"No namespace paths available for {logical}")
|
||||
|
||||
iso.add_file(str(source), **paths)
|
||||
|
||||
|
||||
def sync_file(iso, tree: Path, logical: PurePosixPath) -> None:
|
||||
source = tree / str(logical).lstrip("/")
|
||||
if not source.is_file():
|
||||
raise PrototypeError(f"Replacement does not exist: {source}")
|
||||
removed = remove_logical(iso, logical)
|
||||
if not removed:
|
||||
|
||||
# Preserve the exact namespaces and spellings imported from the source ISO.
|
||||
# Some Microsoft media expose a file through UDF/Joliet but not through the
|
||||
# ISO9660 tree. Reconstructing all three paths can therefore reference a
|
||||
# parent directory that does not exist and makes PyCdlib raise
|
||||
# "Could not find path".
|
||||
found = find_existing_record(iso, logical)
|
||||
if not found:
|
||||
raise PrototypeError(
|
||||
f"Cannot map existing file {logical} in ISO9660, Joliet, or UDF; refusing replacement"
|
||||
)
|
||||
add_file_all_namespaces(iso, source, logical)
|
||||
|
||||
print(" Existing namespace paths:")
|
||||
for namespace, path in found.items():
|
||||
print(f" {namespace}: {path}")
|
||||
|
||||
remove_found_record(iso, found)
|
||||
add_file_all_namespaces(iso, source, logical, found)
|
||||
|
||||
|
||||
def sync_tree(iso, tree: Path, logical_root: PurePosixPath) -> None:
|
||||
|
||||
Reference in New Issue
Block a user