Migra configurazione robocopy a porta SMB

This commit is contained in:
2026-07-01 12:48:39 +02:00
parent fa556ffbd4
commit 3573b4c149
3 changed files with 59 additions and 4 deletions

View File

@@ -89,7 +89,11 @@ def load_config(path: Path | None = None) -> AppConfig:
def load_config_data(path: Path | None = None) -> dict[str, Any]:
config_path = ensure_default_config(path)
return tomllib.loads(config_path.read_text(encoding="utf-8"))
data = tomllib.loads(config_path.read_text(encoding="utf-8"))
migrated = migrate_config_data(data)
if migrated:
save_config_data(data, config_path)
return data
def save_config_data(data: dict[str, Any], path: Path | None = None) -> Path:
@@ -99,6 +103,38 @@ def save_config_data(data: dict[str, Any], path: Path | None = None) -> Path:
return config_path
def migrate_config_data(data: dict[str, Any]) -> bool:
backup = data.get("backup")
if not isinstance(backup, dict):
return False
changed = False
engine = str(backup.get("engine", "robocopy")).lower()
if "engine" not in backup:
backup["engine"] = engine
changed = True
if engine == "robocopy":
if "robocopy_path" not in backup:
backup["robocopy_path"] = "robocopy"
changed = True
server_check = backup.setdefault("server_check", {})
if isinstance(server_check, dict) and int(server_check.get("port", 22)) == 22:
server_check["port"] = 445
changed = True
destinations = backup.get("remote_destinations")
if not isinstance(destinations, list):
legacy_destination = str(backup.get("remote_destination", "")).strip()
backup["remote_destinations"] = (
[legacy_destination] if _is_windows_destination(legacy_destination) else []
)
changed = True
return changed
def parse_config(data: dict[str, Any], path: Path) -> AppConfig:
service = data.get("service", {})
tray = data.get("tray", {})