|
@@ -1558,7 +1558,7 @@ def manage_mod_ui_nam_models(action, config, registry, state):
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def deploy_mod_ui(action, config, registry):
|
|
|
|
|
|
|
+def deploy_mod_ui(action, config, registry, force_reference=False):
|
|
|
if action == "install":
|
|
if action == "install":
|
|
|
if "mod_host_ports" not in registry:
|
|
if "mod_host_ports" not in registry:
|
|
|
raise RuntimeError("install mod-host-ports before installing mod-ui")
|
|
raise RuntimeError("install mod-host-ports before installing mod-ui")
|
|
@@ -1597,8 +1597,17 @@ def deploy_mod_ui(action, config, registry):
|
|
|
trusted_reference_sha256 = None
|
|
trusted_reference_sha256 = None
|
|
|
if reference_record.get("destination") == str(unit["reference_bundle"]):
|
|
if reference_record.get("destination") == str(unit["reference_bundle"]):
|
|
|
trusted_reference_sha256 = reference_record.get("installed_sha256")
|
|
trusted_reference_sha256 = reference_record.get("installed_sha256")
|
|
|
|
|
+ if force_reference and (
|
|
|
|
|
+ not isinstance(trusted_reference_sha256, str)
|
|
|
|
|
+ or not trusted_reference_sha256
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ "--force-reference requires a registry-managed reference bundle at the generated path"
|
|
|
|
|
+ )
|
|
|
reference_sha256 = prepare_mod_ui_reference_bundle(
|
|
reference_sha256 = prepare_mod_ui_reference_bundle(
|
|
|
- unit, trusted_existing_sha256=trusted_reference_sha256
|
|
|
|
|
|
|
+ unit,
|
|
|
|
|
+ trusted_existing_sha256=trusted_reference_sha256,
|
|
|
|
|
+ force_reference=force_reference,
|
|
|
)
|
|
)
|
|
|
if "mod_ui" in registry:
|
|
if "mod_ui" in registry:
|
|
|
registry["mod_ui"]["reference_bundle"] = {
|
|
registry["mod_ui"]["reference_bundle"] = {
|
|
@@ -1635,8 +1644,9 @@ def next_reset_backup_path(path):
|
|
|
return candidate
|
|
return candidate
|
|
|
|
|
|
|
|
|
|
|
|
|
-def next_mod_ui_reference_backup_path(destination):
|
|
|
|
|
- base = destination.with_name(destination.name + ".rigforge-corrupt-backup")
|
|
|
|
|
|
|
+def next_mod_ui_reference_backup_path(destination, forced=False):
|
|
|
|
|
+ suffix = "force-backup" if forced else "corrupt-backup"
|
|
|
|
|
+ base = destination.with_name(destination.name + f".rigforge-{suffix}")
|
|
|
candidate = base
|
|
candidate = base
|
|
|
suffix = 2
|
|
suffix = 2
|
|
|
while candidate.exists() or candidate.is_symlink():
|
|
while candidate.exists() or candidate.is_symlink():
|
|
@@ -1646,7 +1656,9 @@ def next_mod_ui_reference_backup_path(destination):
|
|
|
return candidate
|
|
return candidate
|
|
|
|
|
|
|
|
|
|
|
|
|
-def prepare_mod_ui_reference_bundle(unit, trusted_existing_sha256=None):
|
|
|
|
|
|
|
+def prepare_mod_ui_reference_bundle(
|
|
|
|
|
+ unit, trusted_existing_sha256=None, force_reference=False
|
|
|
|
|
+):
|
|
|
destination = unit["reference_bundle"]
|
|
destination = unit["reference_bundle"]
|
|
|
files = unit["reference_files"]
|
|
files = unit["reference_files"]
|
|
|
validate_user_destination(destination)
|
|
validate_user_destination(destination)
|
|
@@ -1661,9 +1673,12 @@ def prepare_mod_ui_reference_bundle(unit, trusted_existing_sha256=None):
|
|
|
current_files[path.relative_to(destination).as_posix()] = path.read_bytes()
|
|
current_files[path.relative_to(destination).as_posix()] = path.read_bytes()
|
|
|
if current_files != files:
|
|
if current_files != files:
|
|
|
current_sha256 = tree_sha256(destination)
|
|
current_sha256 = tree_sha256(destination)
|
|
|
- if (
|
|
|
|
|
- trusted_existing_sha256 is None
|
|
|
|
|
- or current_sha256 != trusted_existing_sha256
|
|
|
|
|
|
|
+ matches_registry = (
|
|
|
|
|
+ trusted_existing_sha256 is not None
|
|
|
|
|
+ and current_sha256 == trusted_existing_sha256
|
|
|
|
|
+ )
|
|
|
|
|
+ if not matches_registry and not (
|
|
|
|
|
+ force_reference and trusted_existing_sha256 is not None
|
|
|
):
|
|
):
|
|
|
raise RuntimeError(f"generated mod-ui reference changed locally: {destination}")
|
|
raise RuntimeError(f"generated mod-ui reference changed locally: {destination}")
|
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -1679,8 +1694,11 @@ def prepare_mod_ui_reference_bundle(unit, trusted_existing_sha256=None):
|
|
|
raise RuntimeError(
|
|
raise RuntimeError(
|
|
|
f"regenerated mod-ui reference unexpectedly matches corrupted data: {destination}"
|
|
f"regenerated mod-ui reference unexpectedly matches corrupted data: {destination}"
|
|
|
)
|
|
)
|
|
|
- backup = next_mod_ui_reference_backup_path(destination)
|
|
|
|
|
|
|
+ backup = next_mod_ui_reference_backup_path(
|
|
|
|
|
+ destination, forced=force_reference and not matches_registry
|
|
|
|
|
+ )
|
|
|
os.replace(destination, backup)
|
|
os.replace(destination, backup)
|
|
|
|
|
+ print(f"Preserved previous mod-ui reference bundle at {backup}")
|
|
|
try:
|
|
try:
|
|
|
os.replace(staged, destination)
|
|
os.replace(staged, destination)
|
|
|
except OSError:
|
|
except OSError:
|
|
@@ -2324,9 +2342,16 @@ def main(argv=None):
|
|
|
"sooperlooper",
|
|
"sooperlooper",
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
|
|
+ parser.add_argument(
|
|
|
|
|
+ "--force-reference",
|
|
|
|
|
+ action="store_true",
|
|
|
|
|
+ help="replace a changed registry-managed mod-ui reference after preserving it",
|
|
|
|
|
+ )
|
|
|
args = parser.parse_args(argv)
|
|
args = parser.parse_args(argv)
|
|
|
if args.action == "reset" and args.target != "mod-ui":
|
|
if args.action == "reset" and args.target != "mod-ui":
|
|
|
parser.error("reset is only supported for mod-ui")
|
|
parser.error("reset is only supported for mod-ui")
|
|
|
|
|
+ if args.force_reference and (args.action != "install" or args.target != "mod-ui"):
|
|
|
|
|
+ parser.error("--force-reference is only valid with install mod-ui")
|
|
|
try:
|
|
try:
|
|
|
state = yaml.safe_load((ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8"))
|
|
state = yaml.safe_load((ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8"))
|
|
|
deployment = load_deployment()
|
|
deployment = load_deployment()
|
|
@@ -2343,7 +2368,12 @@ def main(argv=None):
|
|
|
elif args.target == "mod-host-ports":
|
|
elif args.target == "mod-host-ports":
|
|
|
deploy_mod_host_ports(args.action, deployment["mod_host_ports"], registry)
|
|
deploy_mod_host_ports(args.action, deployment["mod_host_ports"], registry)
|
|
|
elif args.target == "mod-ui":
|
|
elif args.target == "mod-ui":
|
|
|
- deploy_mod_ui(args.action, deployment["mod_ui"], registry)
|
|
|
|
|
|
|
+ deploy_mod_ui(
|
|
|
|
|
+ args.action,
|
|
|
|
|
+ deployment["mod_ui"],
|
|
|
|
|
+ registry,
|
|
|
|
|
+ force_reference=args.force_reference,
|
|
|
|
|
+ )
|
|
|
elif args.target == "reconcile":
|
|
elif args.target == "reconcile":
|
|
|
deploy_reconcile(args.action, deployment["reconcile"], registry)
|
|
deploy_reconcile(args.action, deployment["reconcile"], registry)
|
|
|
elif args.target == "midi-bridge":
|
|
elif args.target == "midi-bridge":
|