|
|
@@ -90,8 +90,10 @@ def validate_existing_default(directory):
|
|
|
raise RuntimeError(f"default pedalboard graph is invalid: {directory}")
|
|
|
|
|
|
|
|
|
-def next_backup_path(path, boot_id):
|
|
|
- base = path.with_name(f"{path.name}.rigforge-boot-backup-{boot_id}")
|
|
|
+def next_backup_path(path, boot_id, backup_directory=None):
|
|
|
+ parent = backup_directory or path.parent
|
|
|
+ parent.mkdir(parents=True, exist_ok=True)
|
|
|
+ base = parent / f"{path.name}.rigforge-boot-backup-{boot_id}"
|
|
|
candidate = base
|
|
|
suffix = 2
|
|
|
while candidate.exists() or candidate.is_symlink():
|
|
|
@@ -100,6 +102,44 @@ def next_backup_path(path, boot_id):
|
|
|
return candidate
|
|
|
|
|
|
|
|
|
+def is_legacy_pedalboard_backup(path):
|
|
|
+ return (
|
|
|
+ path.name == "default.pedalboard.rigforge-backup"
|
|
|
+ or path.name.startswith("default.pedalboard.rigforge-reset-backup")
|
|
|
+ or path.name.startswith("default.pedalboard.rigforge-boot-backup-")
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def next_migrated_backup_path(backup_directory, original, boot_id):
|
|
|
+ candidate = backup_directory / original.name
|
|
|
+ if not candidate.exists() and not candidate.is_symlink():
|
|
|
+ return candidate
|
|
|
+ base = backup_directory / f"{original.name}.migrated-{boot_id}"
|
|
|
+ candidate = base
|
|
|
+ suffix = 2
|
|
|
+ while candidate.exists() or candidate.is_symlink():
|
|
|
+ candidate = backup_directory / f"{base.name}.{suffix}"
|
|
|
+ suffix += 1
|
|
|
+ return candidate
|
|
|
+
|
|
|
+
|
|
|
+def migrate_legacy_pedalboard_backups(pedalboards, backup_directory, boot_id):
|
|
|
+ if not pedalboards.is_dir() or pedalboards.is_symlink():
|
|
|
+ return
|
|
|
+ legacy = sorted(path for path in pedalboards.iterdir() if is_legacy_pedalboard_backup(path))
|
|
|
+ if not legacy:
|
|
|
+ return
|
|
|
+ backup_directory.mkdir(parents=True, exist_ok=True)
|
|
|
+ for path in legacy:
|
|
|
+ if path.is_symlink():
|
|
|
+ raise RuntimeError(f"refusing to migrate a symlinked pedalboard backup: {path}")
|
|
|
+ if not path.is_dir():
|
|
|
+ raise RuntimeError(f"legacy pedalboard backup is not a directory: {path}")
|
|
|
+ destination = next_migrated_backup_path(backup_directory, path, boot_id)
|
|
|
+ os.replace(path, destination)
|
|
|
+ print(f"Moved legacy mod-ui backup outside pedalboard scan path: {destination}")
|
|
|
+
|
|
|
+
|
|
|
def write_staged_bundle(files, destination):
|
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
staged = Path(
|
|
|
@@ -140,6 +180,12 @@ def prepare_pedalboard(state, repo_root, home, runtime_dir, boot_id):
|
|
|
home, Path(config["pedalboards_directory"]) / "default.pedalboard"
|
|
|
)
|
|
|
last_state = destination_under_home(home, config["last_state_file"])
|
|
|
+ backup_directory = destination_under_home(
|
|
|
+ home, Path(config["last_state_file"]).parent / "boot-backups"
|
|
|
+ )
|
|
|
+ migrate_legacy_pedalboard_backups(
|
|
|
+ default_board.parent, backup_directory, boot_id
|
|
|
+ )
|
|
|
|
|
|
if marker.is_file() and marker.read_text(encoding="utf-8").strip() == boot_id:
|
|
|
validate_existing_default(default_board)
|
|
|
@@ -191,11 +237,11 @@ def prepare_pedalboard(state, repo_root, home, runtime_dir, boot_id):
|
|
|
os.replace(reference, backup)
|
|
|
backups.append((reference, backup))
|
|
|
if default_board.exists():
|
|
|
- backup = next_backup_path(default_board, boot_id)
|
|
|
+ backup = next_backup_path(default_board, boot_id, backup_directory)
|
|
|
os.replace(default_board, backup)
|
|
|
backups.append((default_board, backup))
|
|
|
if last_state.exists():
|
|
|
- backup = next_backup_path(last_state, boot_id)
|
|
|
+ backup = next_backup_path(last_state, boot_id, backup_directory)
|
|
|
os.replace(last_state, backup)
|
|
|
backups.append((last_state, backup))
|
|
|
|