fix: remove legacy config migration — new Verstak starts clean
This commit is contained in:
parent
e9758ec1b5
commit
dd199f38ee
Binary file not shown.
|
|
@ -61,7 +61,6 @@ func NewDefaultManager() *Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load reads app settings from disk, creating defaults if missing.
|
// Load reads app settings from disk, creating defaults if missing.
|
||||||
// Supports migration from legacy v1 config format (vault_path field).
|
|
||||||
func (m *Manager) Load() error {
|
func (m *Manager) Load() error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
@ -75,26 +74,6 @@ func (m *Manager) Load() error {
|
||||||
return fmt.Errorf("failed to read app settings: %w", err)
|
return fmt.Errorf("failed to read app settings: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to detect legacy format (has "vault_path" instead of "currentVaultPath")
|
|
||||||
var raw map[string]interface{}
|
|
||||||
if err := json.Unmarshal(data, &raw); err == nil {
|
|
||||||
if _, hasLegacy := raw["vault_path"]; hasLegacy {
|
|
||||||
// Legacy v1 config — migrate
|
|
||||||
m.config = defaultConfig()
|
|
||||||
if vp, ok := raw["vault_path"].(string); ok && vp != "" {
|
|
||||||
m.config.CurrentVaultPath = vp
|
|
||||||
}
|
|
||||||
if theme, ok := raw["theme"].(string); ok && theme != "" {
|
|
||||||
m.config.Theme = theme
|
|
||||||
}
|
|
||||||
// Save migrated config
|
|
||||||
if err := m.saveLocked(); err != nil {
|
|
||||||
return fmt.Errorf("failed to save migrated config: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var cfg Config
|
var cfg Config
|
||||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||||
// Corrupt config: backup and create defaults
|
// Corrupt config: backup and create defaults
|
||||||
|
|
|
||||||
|
|
@ -131,35 +131,3 @@ func TestAppSettings_NotInsideVault(t *testing.T) {
|
||||||
t.Errorf("app settings path should be under .config/verstak, got %s", path)
|
t.Errorf("app settings path should be under .config/verstak, got %s", path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoad_LegacyMigration(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
path := filepath.Join(dir, "config.json")
|
|
||||||
|
|
||||||
// Write a legacy v1 config
|
|
||||||
legacy := `{
|
|
||||||
"version": 1,
|
|
||||||
"vault_path": "/home/user/Documents/MyVault",
|
|
||||||
"theme": "light",
|
|
||||||
"first_run_completed": true
|
|
||||||
}`
|
|
||||||
if err := os.WriteFile(path, []byte(legacy), 0o600); err != nil {
|
|
||||||
t.Fatalf("write legacy config: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
m := NewManager(path)
|
|
||||||
if err := m.Load(); err != nil {
|
|
||||||
t.Fatalf("Load: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg := m.Get()
|
|
||||||
if cfg.CurrentVaultPath != "/home/user/Documents/MyVault" {
|
|
||||||
t.Errorf("CurrentVaultPath: got %q, want %q", cfg.CurrentVaultPath, "/home/user/Documents/MyVault")
|
|
||||||
}
|
|
||||||
if cfg.Theme != "light" {
|
|
||||||
t.Errorf("Theme: got %q, want %q", cfg.Theme, "light")
|
|
||||||
}
|
|
||||||
if cfg.SchemaVersion != 1 {
|
|
||||||
t.Errorf("SchemaVersion: got %d, want 1", cfg.SchemaVersion)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue