Skip to content

Commit 334098c

Browse files
authored
Don't delete legacy files after migration. (#281)
1 parent 845a012 commit 334098c

File tree

2 files changed

+0
-132
lines changed

2 files changed

+0
-132
lines changed

pkg/migrate/migrate.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"os"
9-
"path/filepath"
109
"strings"
1110

1211
legacycatalog "github.com/docker/mcp-gateway/pkg/catalog"
@@ -74,12 +73,6 @@ func MigrateConfig(ctx context.Context, docker docker.Client, dao db.DAO) {
7473

7574
// Migration considered successful by this point
7675
status = MigrationStatusSuccess
77-
78-
err = backupLegacyFiles()
79-
if err != nil {
80-
logs = append(logs, fmt.Sprintf("failed to backup legacy files: %s", err.Error()))
81-
return
82-
}
8376
}
8477

8578
func createDefaultProfile(ctx context.Context, dao db.DAO, registry *config.Registry, cfg map[string]map[string]any, tools *config.ToolsConfig, oldCatalog *legacycatalog.Catalog) ([]string, error) {
@@ -187,66 +180,3 @@ func readLegacyDefaults(ctx context.Context, docker docker.Client) (*config.Regi
187180

188181
return &registry, cfg, &tools, &mcpCatalog, nil
189182
}
190-
191-
func backupLegacyFiles() error {
192-
// Create backup directory
193-
backupDir, err := config.FilePath(".backup")
194-
if err != nil {
195-
return fmt.Errorf("failed to get backup directory path: %w", err)
196-
}
197-
198-
err = os.MkdirAll(backupDir, 0o755)
199-
if err != nil {
200-
return fmt.Errorf("failed to create backup directory: %w", err)
201-
}
202-
203-
// Get paths to legacy files
204-
registryPath, err := config.FilePath("registry.yaml")
205-
if err != nil {
206-
return fmt.Errorf("failed to get registry path: %w", err)
207-
}
208-
configPath, err := config.FilePath("config.yaml")
209-
if err != nil {
210-
return fmt.Errorf("failed to get config path: %w", err)
211-
}
212-
toolsPath, err := config.FilePath("tools.yaml")
213-
if err != nil {
214-
return fmt.Errorf("failed to get tools path: %w", err)
215-
}
216-
217-
catalogIndexPath, err := config.FilePath("catalog.json")
218-
if err != nil {
219-
return fmt.Errorf("failed to get catalog index path: %w", err)
220-
}
221-
222-
catalogsDir, err := config.FilePath("catalogs")
223-
if err != nil {
224-
return fmt.Errorf("failed to get old catalog path: %w", err)
225-
}
226-
227-
oldCatalogPath := filepath.Join(catalogsDir, legacycatalog.DockerCatalogFilename)
228-
229-
// Move files to backup directory
230-
_ = moveFile(registryPath, filepath.Join(backupDir, "registry.yaml"))
231-
_ = moveFile(configPath, filepath.Join(backupDir, "config.yaml"))
232-
_ = moveFile(toolsPath, filepath.Join(backupDir, "tools.yaml"))
233-
_ = moveFile(catalogIndexPath, filepath.Join(backupDir, "catalog.json"))
234-
_ = moveFile(oldCatalogPath, filepath.Join(backupDir, legacycatalog.DockerCatalogFilename))
235-
236-
// We use os.Remove to remove the directory, so it's only removed if empty
237-
// We don't want to remove any custom catalog yamls the user may have added
238-
_ = os.Remove(catalogsDir)
239-
240-
return nil
241-
}
242-
243-
// moveFile moves a file from src to dst. If src doesn't exist, it's a no-op.
244-
func moveFile(src, dst string) error {
245-
// Check if source file exists
246-
if _, err := os.Stat(src); os.IsNotExist(err) {
247-
return nil // File doesn't exist, nothing to move
248-
}
249-
250-
// Move the file
251-
return os.Rename(src, dst)
252-
}

pkg/migrate/migrate_test.go

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ func TestMigrateConfig_SuccessWithServers(t *testing.T) {
122122
// Verify secrets
123123
assert.Len(t, workingSets[0].Secrets, 1)
124124
assert.Equal(t, "docker-desktop-store", workingSets[0].Secrets["default"].Provider)
125-
126-
// Verify legacy files were backed up
127-
assertLegacyFilesBackedUp(t, mcpDir)
128125
}
129126

130127
func TestMigrateConfig_SuccessWithSingleServer(t *testing.T) {
@@ -184,9 +181,6 @@ func TestMigrateConfig_SkipsWithNoServers(t *testing.T) {
184181
workingSets, err := dao.ListWorkingSets(ctx)
185182
require.NoError(t, err)
186183
assert.Empty(t, workingSets)
187-
188-
// Verify legacy files were still backed up
189-
assertLegacyFilesBackedUp(t, mcpDir)
190184
}
191185

192186
func TestMigrateConfig_FailureReadingLegacyFiles(t *testing.T) {
@@ -485,18 +479,6 @@ func TestMigrateConfig_LegacyFilesBackedUpOnSuccess(t *testing.T) {
485479
status, err := dao.GetMigrationStatus(ctx)
486480
require.NoError(t, err)
487481
assert.Equal(t, MigrationStatusSuccess, status.Status)
488-
489-
// Verify all legacy files were backed up
490-
assertLegacyFilesBackedUp(t, mcpDir)
491-
492-
// Verify catalog.json was also backed up
493-
backupCatalogIndexPath := filepath.Join(mcpDir, ".backup", "catalog.json")
494-
_, err = os.Stat(backupCatalogIndexPath)
495-
assert.False(t, os.IsNotExist(err), "catalog.json should be backed up")
496-
497-
// Verify original catalog.json no longer exists
498-
_, err = os.Stat(catalogIndexPath)
499-
assert.True(t, os.IsNotExist(err), "original catalog.json should be removed")
500482
}
501483

502484
// Helper functions
@@ -546,50 +528,6 @@ func writeCatalogFile(t *testing.T, mcpDir string, serverNames []string) {
546528
require.NoError(t, err)
547529
}
548530

549-
func assertLegacyFilesBackedUp(t *testing.T, mcpDir string) {
550-
t.Helper()
551-
552-
backupDir := filepath.Join(mcpDir, ".backup")
553-
554-
// Verify backup directory exists
555-
_, err := os.Stat(backupDir)
556-
assert.False(t, os.IsNotExist(err), "backup directory should exist")
557-
558-
// Verify original files no longer exist in original location
559-
registryPath := filepath.Join(mcpDir, "registry.yaml")
560-
_, err = os.Stat(registryPath)
561-
assert.True(t, os.IsNotExist(err), "original registry.yaml should be removed")
562-
563-
configPath := filepath.Join(mcpDir, "config.yaml")
564-
_, err = os.Stat(configPath)
565-
assert.True(t, os.IsNotExist(err), "original config.yaml should be removed")
566-
567-
toolsPath := filepath.Join(mcpDir, "tools.yaml")
568-
_, err = os.Stat(toolsPath)
569-
assert.True(t, os.IsNotExist(err), "original tools.yaml should be removed")
570-
571-
catalogPath := filepath.Join(mcpDir, "catalogs", legacycatalog.DockerCatalogFilename)
572-
_, err = os.Stat(catalogPath)
573-
assert.True(t, os.IsNotExist(err), "original catalog file should be removed")
574-
575-
// Verify files exist in backup directory
576-
backupRegistryPath := filepath.Join(backupDir, "registry.yaml")
577-
_, err = os.Stat(backupRegistryPath)
578-
assert.False(t, os.IsNotExist(err), "registry.yaml should be backed up")
579-
580-
backupConfigPath := filepath.Join(backupDir, "config.yaml")
581-
_, err = os.Stat(backupConfigPath)
582-
assert.False(t, os.IsNotExist(err), "config.yaml should be backed up")
583-
584-
backupToolsPath := filepath.Join(backupDir, "tools.yaml")
585-
_, err = os.Stat(backupToolsPath)
586-
assert.False(t, os.IsNotExist(err), "tools.yaml should be backed up")
587-
588-
backupCatalogPath := filepath.Join(backupDir, legacycatalog.DockerCatalogFilename)
589-
_, err = os.Stat(backupCatalogPath)
590-
assert.False(t, os.IsNotExist(err), "catalog file should be backed up")
591-
}
592-
593531
// mockDockerClient is a simple mock implementation of docker.Client for testing
594532
type mockDockerClient struct {
595533
inspectVolumeFunc func(ctx context.Context, name string) (volume.Volume, error)

0 commit comments

Comments
 (0)