Update iso-prototype.py

This commit is contained in:
Kroese
2026-07-28 13:06:44 +02:00
committed by GitHub
parent 5fffd5416e
commit 48cc11c393
+24 -4
View File
@@ -403,8 +403,19 @@ def remove_logical(iso, logical: PurePosixPath) -> bool:
found = find_existing_record(iso, logical)
if not found:
return False
iso.rm_file(**found)
return True
# 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.
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 False
def add_file_all_namespaces(iso, source: Path, logical: PurePosixPath) -> None:
@@ -457,12 +468,19 @@ def build_pycdlib(args: argparse.Namespace) -> None:
iso = pycdlib.PyCdlib()
try:
print(f"Opening source ISO: {source}")
iso.open(str(source))
for value in args.replace:
sync_file(iso, tree, PurePosixPath("/") / value.lstrip("/"))
logical = PurePosixPath("/") / value.lstrip("/")
print(f"Replacing: {logical}")
sync_file(iso, tree, logical)
for value in args.add_tree:
sync_tree(iso, tree, PurePosixPath("/") / value.lstrip("/"))
logical = PurePosixPath("/") / value.lstrip("/")
print(f"Synchronizing tree: {logical}")
sync_tree(iso, tree, logical)
print("Checking PyCdlib consistency...")
iso.force_consistency()
print(f"Writing output ISO: {output}")
iso.write(str(output))
finally:
iso.close()
@@ -525,7 +543,9 @@ def main() -> int:
print(f"ERROR: {exc}", file=sys.stderr)
return 1
except Exception as exc:
import traceback
print(f"UNEXPECTED ERROR: {type(exc).__name__}: {exc}", file=sys.stderr)
traceback.print_exc()
return 2
return 0