Skip to content

Commit 79d4b7d

Browse files
author
LittleCoinCoin
committed
fix(backup): preserve original filename in backup creation
Changed backup filename generation to preserve the original config filename (e.g., config.toml, mcp.json) instead of hardcoding 'mcp.json' prefix. This ensures Codex TOML backups are correctly named config.toml.{hostname}.{timestamp}. - Updated create_backup() to use config_path.name instead of hardcoded prefix - Updated BackupInfo.backup_name property to return actual filename - Fixes backup restoration and listing for non-JSON config formats
1 parent 257fe80 commit 79d4b7d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

hatch/mcp_host_config/backup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def validate_file_exists(cls, v):
5353
@property
5454
def backup_name(self) -> str:
5555
"""Get backup filename."""
56-
return f"mcp.json.{self.hostname}.{self.timestamp.strftime('%Y%m%d_%H%M%S_%f')}"
56+
# Extract original filename from backup path if available
57+
# Backup filename format: {original_name}.{hostname}.{timestamp}
58+
return self.file_path.name
5759

5860
@property
5961
def age_days(self) -> int:
@@ -255,8 +257,10 @@ def create_backup(self, config_path: Path, hostname: str) -> BackupResult:
255257
host_backup_dir.mkdir(exist_ok=True)
256258

257259
# Generate timestamped backup filename with microseconds for uniqueness
260+
# Preserve original filename instead of hardcoding 'mcp.json'
258261
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
259-
backup_name = f"mcp.json.{hostname}.{timestamp}"
262+
original_filename = config_path.name
263+
backup_name = f"{original_filename}.{hostname}.{timestamp}"
260264
backup_path = host_backup_dir / backup_name
261265

262266
# Get original file size

0 commit comments

Comments
 (0)