Skip to content

Commit f7af78a

Browse files
author
LittleCoinCoin
committed
fix: backup system filename format
Root cause: Package sync command was passing MCPHostType enum objects instead of string values to backup system, creating filenames like 'mcp.json.MCPHostType.GEMINI.*' instead of 'mcp.json.gemini.*' Changes: - Fix sync command to pass host.value (string) instead of host (enum object) - Add backward compatibility to backup discovery for legacy incorrect filenames - Replace Unicode symbols with ASCII-compatible text for better compatibility Resolves backup system malfunction where existing backups couldn't be found by list/restore commands despite files existing on disk. Tested: All backup operations (list, restore) now work correctly with both new correct format and existing legacy format backup files.
1 parent e355bd7 commit f7af78a

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

hatch/cli_hatch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,19 +1166,19 @@ def main():
11661166
for host in hosts:
11671167
try:
11681168
result = mcp_manager.configure_server(
1169-
hostname=host,
1169+
hostname=host.value, # Use enum value (string) instead of enum object
11701170
server_config=server_config,
11711171
no_backup=args.no_backup
11721172
)
11731173

11741174
if result.success:
1175-
print(f" Successfully configured {server_config.name} on {host.value}")
1175+
print(f"[SUCCESS] Successfully configured {server_config.name} on {host.value}")
11761176
success_count += 1
11771177
else:
1178-
print(f" Failed to configure {server_config.name} on {host.value}: {result.error_message}")
1178+
print(f"[ERROR] Failed to configure {server_config.name} on {host.value}: {result.error_message}")
11791179

11801180
except Exception as e:
1181-
print(f" Error configuring {server_config.name} on {host.value}: {e}")
1181+
print(f"[ERROR] Error configuring {server_config.name} on {host.value}: {e}")
11821182

11831183
# Report results
11841184
if success_count == len(hosts):

hatch/mcp_host_config/backup.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,26 +306,32 @@ def list_backups(self, hostname: str) -> List[BackupInfo]:
306306
return []
307307

308308
backups = []
309-
pattern = f"mcp.json.{hostname}.*"
310-
311-
for backup_file in host_backup_dir.glob(pattern):
312-
try:
313-
# Parse timestamp from filename
314-
timestamp_str = backup_file.name.split('.')[-1]
315-
timestamp = datetime.strptime(timestamp_str, "%Y%m%d_%H%M%S_%f")
316-
317-
backup_info = BackupInfo(
318-
hostname=hostname,
319-
timestamp=timestamp,
320-
file_path=backup_file,
321-
file_size=backup_file.stat().st_size,
322-
original_config_path=Path("placeholder") # Will be implemented in host config phase
323-
)
324-
backups.append(backup_info)
325-
326-
except (ValueError, OSError):
327-
# Skip invalid backup files
328-
continue
309+
310+
# Search for both correct format and legacy incorrect format for backward compatibility
311+
patterns = [
312+
f"mcp.json.{hostname}.*", # Correct format: mcp.json.gemini.*
313+
f"mcp.json.MCPHostType.{hostname.upper()}.*" # Legacy incorrect format: mcp.json.MCPHostType.GEMINI.*
314+
]
315+
316+
for pattern in patterns:
317+
for backup_file in host_backup_dir.glob(pattern):
318+
try:
319+
# Parse timestamp from filename
320+
timestamp_str = backup_file.name.split('.')[-1]
321+
timestamp = datetime.strptime(timestamp_str, "%Y%m%d_%H%M%S_%f")
322+
323+
backup_info = BackupInfo(
324+
hostname=hostname,
325+
timestamp=timestamp,
326+
file_path=backup_file,
327+
file_size=backup_file.stat().st_size,
328+
original_config_path=Path("placeholder") # Will be implemented in host config phase
329+
)
330+
backups.append(backup_info)
331+
332+
except (ValueError, OSError):
333+
# Skip invalid backup files
334+
continue
329335

330336
# Sort by timestamp (newest first)
331337
return sorted(backups, key=lambda b: b.timestamp, reverse=True)

0 commit comments

Comments
 (0)