From 4517bfe292a465eff85ed2cf285f517007243841 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 3 Jul 2026 10:54:23 -0500 Subject: [PATCH] refactor(config): separate config dir from data dir on unix Unix path managers resolved ConfigDir and DataDir to the same ~/.devsy path, so config.yaml piled into the data root alongside contexts and bind-mount sources. Move ConfigDir to ~/.config/devsy, matching Windows' already-distinct layout. DataDir/StateDir/CacheDir are unchanged. Also unify the pm self-reference assignment (pm.pm = pm) across darwin and windows to match linux and clear the staticcheck finding. --- pkg/config/pathmanager_darwin.go | 4 +- pkg/config/pathmanager_darwin_test.go | 57 +++++++++++++++++++++++++++ pkg/config/pathmanager_linux.go | 2 +- pkg/config/pathmanager_linux_test.go | 4 +- pkg/config/pathmanager_windows.go | 2 +- 5 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 pkg/config/pathmanager_darwin_test.go diff --git a/pkg/config/pathmanager_darwin.go b/pkg/config/pathmanager_darwin.go index bf04565f1..8b36cd827 100644 --- a/pkg/config/pathmanager_darwin.go +++ b/pkg/config/pathmanager_darwin.go @@ -14,7 +14,7 @@ type darwinPathManager struct { func newPlatformPathManager() PathManager { pm := &darwinPathManager{} - pm.basePathManager.pm = pm + pm.pm = pm return pm } @@ -25,7 +25,7 @@ func (d *darwinPathManager) ConfigDir() (string, error) { return "", fmt.Errorf("config dir: %w", err) } - return ensureDir(filepath.Join(home, "."+RepoName)) + return ensureDir(filepath.Join(home, ".config", RepoName)) } func (d *darwinPathManager) DataDir() (string, error) { diff --git a/pkg/config/pathmanager_darwin_test.go b/pkg/config/pathmanager_darwin_test.go new file mode 100644 index 000000000..949bc0674 --- /dev/null +++ b/pkg/config/pathmanager_darwin_test.go @@ -0,0 +1,57 @@ +//go:build darwin + +package config + +import ( + "path/filepath" + "testing" +) + +func newTestDarwinPM() PathManager { + pm := &darwinPathManager{} + pm.pm = pm + + return pm +} + +func TestDarwinConfigDir_IsUnderXDGConfig(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + + pm := newTestDarwinPM() + + got, err := pm.ConfigDir() + if err != nil { + t.Fatalf("ConfigDir: %v", err) + } + + want := filepath.Join(home, ".config", RepoName) + if got != want { + t.Errorf("ConfigDir = %q, want %q", got, want) + } + + dataDir, err := pm.DataDir() + if err != nil { + t.Fatalf("DataDir: %v", err) + } + if got == dataDir { + t.Errorf("ConfigDir and DataDir must be distinct, both = %q", got) + } +} + +func TestDarwinConfigFilePath(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv(EnvConfig, "") + + pm := newTestDarwinPM() + got, err := pm.ConfigFilePath() + if err != nil { + t.Fatalf("ConfigFilePath: %v", err) + } + + want := filepath.Join(home, ".config", RepoName, ConfigFile) + if got != want { + t.Errorf("got %q, want %q", got, want) + } +} diff --git a/pkg/config/pathmanager_linux.go b/pkg/config/pathmanager_linux.go index 5861646f2..8581fb1dc 100644 --- a/pkg/config/pathmanager_linux.go +++ b/pkg/config/pathmanager_linux.go @@ -25,7 +25,7 @@ func (l *linuxPathManager) ConfigDir() (string, error) { return "", fmt.Errorf("config dir: %w", err) } - return ensureDir(filepath.Join(home, "."+RepoName)) + return ensureDir(filepath.Join(home, ".config", RepoName)) } func (l *linuxPathManager) DataDir() (string, error) { diff --git a/pkg/config/pathmanager_linux_test.go b/pkg/config/pathmanager_linux_test.go index 58d0b0455..7e9c6efba 100644 --- a/pkg/config/pathmanager_linux_test.go +++ b/pkg/config/pathmanager_linux_test.go @@ -45,7 +45,7 @@ func TestLinuxDefaults(t *testing.T) { fn func() (string, error) want string }{ - {"ConfigDir", pm.ConfigDir, filepath.Join(home, "."+RepoName)}, + {"ConfigDir", pm.ConfigDir, filepath.Join(home, ".config", RepoName)}, {"DataDir", pm.DataDir, filepath.Join(home, "."+RepoName)}, {"CacheDir", pm.CacheDir, filepath.Join(home, ".cache", RepoName)}, {"StateDir", pm.StateDir, filepath.Join(home, "."+RepoName, "state")}, @@ -79,7 +79,7 @@ func TestConfigFilePathDefault(t *testing.T) { t.Fatalf("unexpected error: %v", err) } - want := filepath.Join(home, "."+RepoName, ConfigFile) + want := filepath.Join(home, ".config", RepoName, ConfigFile) if got != want { t.Errorf("got %q, want %q", got, want) } diff --git a/pkg/config/pathmanager_windows.go b/pkg/config/pathmanager_windows.go index c23da1b8f..944b4bb15 100644 --- a/pkg/config/pathmanager_windows.go +++ b/pkg/config/pathmanager_windows.go @@ -14,7 +14,7 @@ type windowsPathManager struct { func newPlatformPathManager() PathManager { pm := &windowsPathManager{} - pm.basePathManager.pm = pm + pm.pm = pm return pm }