From d2dc293722c25bf16b76fb33dfc345d9a134e6de Mon Sep 17 00:00:00 2001 From: kqjy Date: Sun, 21 Dec 2025 13:17:33 +0800 Subject: [PATCH] Fix inconsistency in config files --- app/__init__.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++--- app/version.py | 2 +- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index b20f44e..cd9e842 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -2,13 +2,14 @@ from __future__ import annotations import logging +import shutil import sys import time import uuid from logging.handlers import RotatingFileHandler from pathlib import Path from datetime import timedelta -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional from flask import Flask, g, has_request_context, redirect, render_template, request, url_for from flask_cors import CORS @@ -28,6 +29,33 @@ from .storage import ObjectStorage from .version import get_version +def _migrate_config_file(active_path: Path, legacy_paths: List[Path]) -> Path: + """Migrate config file from legacy locations to the active path. + + Checks each legacy path in order and moves the first one found to the active path. + This ensures backward compatibility for users upgrading from older versions. + """ + active_path.parent.mkdir(parents=True, exist_ok=True) + + if active_path.exists(): + return active_path + + for legacy_path in legacy_paths: + if legacy_path.exists(): + try: + shutil.move(str(legacy_path), str(active_path)) + except OSError: + # Fall back to copy + delete if move fails (e.g., cross-device) + shutil.copy2(legacy_path, active_path) + try: + legacy_path.unlink(missing_ok=True) + except OSError: + pass + break + + return active_path + + def create_app( test_config: Optional[Dict[str, Any]] = None, *, @@ -74,8 +102,26 @@ def create_app( secret_store = EphemeralSecretStore(default_ttl=app.config.get("SECRET_TTL_SECONDS", 300)) # Initialize Replication components - connections_path = Path(app.config["STORAGE_ROOT"]) / ".connections.json" - replication_rules_path = Path(app.config["STORAGE_ROOT"]) / ".replication_rules.json" + # Store config files in the system config directory for consistency + storage_root = Path(app.config["STORAGE_ROOT"]) + config_dir = storage_root / ".myfsio.sys" / "config" + config_dir.mkdir(parents=True, exist_ok=True) + + # Define paths with migration from legacy locations + connections_path = _migrate_config_file( + active_path=config_dir / "connections.json", + legacy_paths=[ + storage_root / ".myfsio.sys" / "connections.json", # Previous location + storage_root / ".connections.json", # Original legacy location + ], + ) + replication_rules_path = _migrate_config_file( + active_path=config_dir / "replication_rules.json", + legacy_paths=[ + storage_root / ".myfsio.sys" / "replication_rules.json", # Previous location + storage_root / ".replication_rules.json", # Original legacy location + ], + ) connections = ConnectionStore(connections_path) replication = ReplicationManager(storage, connections, replication_rules_path) diff --git a/app/version.py b/app/version.py index f30bbb3..78d120a 100644 --- a/app/version.py +++ b/app/version.py @@ -1,7 +1,7 @@ """Central location for the application version string.""" from __future__ import annotations -APP_VERSION = "0.1.5" +APP_VERSION = "0.1.6" def get_version() -> str: