|
|
@@ -74,6 +74,8 @@ def load_deployment():
|
|
|
errors.append("NAM LV2 URL must be the approved release asset for the declared tag")
|
|
|
if namlv2.get("bundle_directory") != "neural_amp_modeler.lv2":
|
|
|
errors.append("NAM LV2 bundle directory is invalid")
|
|
|
+ if namlv2.get("backup_directory") != ".local/state/rigforge/namlv2-backups":
|
|
|
+ errors.append("NAM LV2 backup directory is invalid")
|
|
|
source = pipewire.get("fragment_source")
|
|
|
if source != "config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf":
|
|
|
errors.append("PipeWire fragment source is invalid")
|
|
|
@@ -170,6 +172,55 @@ def validate_backup_path(backup, destination, is_directory=False):
|
|
|
return backup_path
|
|
|
|
|
|
|
|
|
+def namlv2_backup_path(config, destination):
|
|
|
+ relative = PurePosixPath(config.get("backup_directory", ""))
|
|
|
+ if relative.is_absolute() or ".." in relative.parts or not relative.parts:
|
|
|
+ raise RuntimeError("NAM LV2 backup directory must be a safe relative path")
|
|
|
+ home = Path.home().resolve()
|
|
|
+ backup_root = (home / Path(*relative.parts)).resolve()
|
|
|
+ if not backup_root.is_relative_to(home):
|
|
|
+ raise RuntimeError("NAM LV2 backup directory escapes the user home directory")
|
|
|
+ backup = backup_root / f"{destination.name}.rigforge-backup"
|
|
|
+ validate_user_destination(backup)
|
|
|
+ return backup
|
|
|
+
|
|
|
+
|
|
|
+def validate_nam_backup_path(backup, destination, config):
|
|
|
+ if backup is None:
|
|
|
+ return None
|
|
|
+ backup_path = Path(backup)
|
|
|
+ approved = {
|
|
|
+ destination.with_name(destination.name + ".rigforge-backup"),
|
|
|
+ namlv2_backup_path(config, destination),
|
|
|
+ }
|
|
|
+ if backup_path not in approved:
|
|
|
+ raise RuntimeError(f"recorded NAM LV2 backup path is outside approved locations: {backup_path}")
|
|
|
+ if backup_path.is_symlink():
|
|
|
+ raise RuntimeError(f"recorded NAM LV2 backup must not be a symlink: {backup_path}")
|
|
|
+ if backup_path.exists() and not backup_path.is_dir():
|
|
|
+ raise RuntimeError(f"recorded NAM LV2 backup has the wrong type: {backup_path}")
|
|
|
+ return backup_path
|
|
|
+
|
|
|
+
|
|
|
+def migrate_namlv2_backup(config, backup, destination, backup_sha256):
|
|
|
+ """Move legacy in-~/.lv2 backups out of Lilv's plugin search path."""
|
|
|
+ if backup is None or not backup.exists():
|
|
|
+ return backup
|
|
|
+ target = namlv2_backup_path(config, destination)
|
|
|
+ if backup == target:
|
|
|
+ return backup
|
|
|
+ legacy = destination.with_name(destination.name + ".rigforge-backup")
|
|
|
+ if backup != legacy:
|
|
|
+ return backup
|
|
|
+ if tree_sha256(backup) != backup_sha256:
|
|
|
+ raise RuntimeError(f"recorded NAM LV2 backup changed locally: {backup}")
|
|
|
+ if target.exists() or target.is_symlink():
|
|
|
+ raise RuntimeError(f"NAM LV2 backup destination already exists: {target}")
|
|
|
+ target.parent.mkdir(parents=True, exist_ok=True)
|
|
|
+ os.replace(backup, target)
|
|
|
+ return target
|
|
|
+
|
|
|
+
|
|
|
def atomic_install(source, destination):
|
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
fd, temporary_name = tempfile.mkstemp(prefix=f".{destination.name}.", dir=destination.parent)
|
|
|
@@ -738,7 +789,9 @@ def deploy_namlv2(action, config, registry):
|
|
|
print("No managed NAM LV2 bundle to uninstall.")
|
|
|
return
|
|
|
if managed.get("pending_uninstall"):
|
|
|
- backup_path = validate_backup_path(managed.get("backup"), destination, is_directory=True)
|
|
|
+ backup_path = validate_nam_backup_path(
|
|
|
+ managed.get("backup"), destination, config
|
|
|
+ )
|
|
|
backup_exists = backup_path is not None and backup_path.is_dir()
|
|
|
if backup_path is not None and backup_path.exists() and not backup_exists:
|
|
|
raise RuntimeError(f"recorded backup has the wrong type: {backup_path}")
|
|
|
@@ -768,7 +821,9 @@ def deploy_namlv2(action, config, registry):
|
|
|
raise RuntimeError(f"managed NAM LV2 path changed: {destination}")
|
|
|
if tree_sha256(destination) != managed.get("installed_sha256"):
|
|
|
raise RuntimeError(f"managed NAM LV2 bundle changed locally; refusing to remove: {destination}")
|
|
|
- backup_path = validate_backup_path(managed.get("backup"), destination, is_directory=True)
|
|
|
+ backup_path = validate_nam_backup_path(
|
|
|
+ managed.get("backup"), destination, config
|
|
|
+ )
|
|
|
if backup_path is not None and not backup_path.is_dir():
|
|
|
raise RuntimeError(f"recorded backup bundle is missing: {backup_path}")
|
|
|
if backup_path is not None and tree_sha256(backup_path) != managed.get("backup_sha256"):
|
|
|
@@ -791,15 +846,22 @@ def deploy_namlv2(action, config, registry):
|
|
|
raise RuntimeError(f"managed NAM LV2 bundle is missing: {destination}")
|
|
|
if tree_sha256(destination) != managed.get("installed_sha256"):
|
|
|
raise RuntimeError(f"managed NAM LV2 bundle changed locally; refusing overwrite: {destination}")
|
|
|
+ backup = validate_nam_backup_path(managed.get("backup"), destination, config)
|
|
|
+ backup_sha256 = managed.get("backup_sha256")
|
|
|
+ if backup is not None:
|
|
|
+ backup = migrate_namlv2_backup(
|
|
|
+ config, backup, destination, backup_sha256
|
|
|
+ )
|
|
|
+ managed["backup"] = str(backup)
|
|
|
+ registry["namlv2"] = managed
|
|
|
+ write_registry(registry)
|
|
|
if managed.get("tag") == config["tag"] and (
|
|
|
artifact_digest is None or managed.get("artifact_sha256") == artifact_digest
|
|
|
):
|
|
|
print(f"NAM LV2 tag {config['tag']} is already installed and unchanged.")
|
|
|
return
|
|
|
- backup = validate_backup_path(managed.get("backup"), destination, is_directory=True)
|
|
|
- backup_sha256 = managed.get("backup_sha256")
|
|
|
elif destination.exists():
|
|
|
- backup = destination.with_name(destination.name + ".rigforge-backup")
|
|
|
+ backup = namlv2_backup_path(config, destination)
|
|
|
if backup.exists():
|
|
|
raise RuntimeError(f"backup path already exists: {backup}")
|
|
|
backup_sha256 = None
|
|
|
@@ -838,6 +900,7 @@ def deploy_namlv2(action, config, registry):
|
|
|
try:
|
|
|
shutil.copytree(extracted_bundle, staged_bundle)
|
|
|
if managed is None and backup is not None:
|
|
|
+ backup.parent.mkdir(parents=True, exist_ok=True)
|
|
|
shutil.copytree(destination, backup)
|
|
|
backup_created = True
|
|
|
backup_sha256 = tree_sha256(backup)
|