Uh oh!
There was an error while loading. Please reload this page.
refactor: migrate os.TempDir() callsites to PathManager (Phase 4) - #78
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
f4d2f03 to
c40da7aCompareUh oh!
There was an error while loading. Please reload this page.
* feat(config): add PathManager interface for XDG-compliant path computation Introduce a PathManager interface that centralises all filesystem path computation for the Devsy CLI with XDG Base Directory compliance on Linux and platform-native conventions on macOS/Windows. This is a pure addition — no existing files are modified, no callsite changes. The interface defines methods for all five XDG category directories (config, data, cache, state, runtime) plus sub-path methods for contexts, workspaces, machines, providers, cache categories, runtime files, and state directories. Per-OS implementations use build tags: Linux reads XDG_* env vars with standard defaults, macOS uses ~/Library paths, Windows uses %APPDATA% and %LOCALAPPDATA%. A shared basePathManager derives all sub-paths from the five top-level directories via self-referencing delegation. Includes a global singleton (DefaultPathManager) with SetPathManager and ResetPathManager for test injection. * fix(config): split pathmanager tests by build tag to fix cross-platform CI Move linux-specific tests (those referencing linuxPathManager) into pathmanager_linux_test.go with a //go:build linux constraint. The generic singleton tests remain in pathmanager_test.go and use NewPathManager() instead of the linux-only helper. Fixes: pathmanager_test.go:14:9: undefined: linuxPathManager on macOS and Windows CI runners. * refactor(platform): migrate legacy .loft cache to PathManager (#76) Replace manual ~/.loft path construction and DEVSY_CACHE_FOLDER env var lookup with PathManager.PlatformCacheDir() for XDG-compliant cache paths. * refactor(config): migrate dir.go and provider/dir.go to use PathManager (#77) Replace manual env-var reads and filepath.Join path construction in GetConfigDir(), GetConfigPath(), and all 11 provider.Get*Dir() functions with delegation to the PathManager singleton introduced in Phase 1. Function signatures and validation (empty ID checks, ToProInstanceID transform) are preserved — no breaking API changes for callers. * refactor: migrate os.TempDir() callsites to PathManager (Phase 4) (#78) * refactor: migrate cache callsites to PathManager (4a, 4b, 4c) * refactor: migrate runtime/state callsites to PathManager (4d, 4e, 4f, 4g, 4h) * fix(config): ensure PathManager directory methods create dirs before returning The per-OS Dir methods (ConfigDir, DataDir, CacheDir, StateDir, RuntimeDir) returned paths to subdirectories that may not exist yet. This caused failures when callers (e.g. flock.New) tried to create files without the parent directory existing — notably inside containers where /tmp/devsy-<uid>/ does not exist by default. Add an ensureDir helper that calls os.MkdirAll(path, 0700) and wire it into every Dir method return path. This matches the XDG convention that applications should create their directories as needed. * fix(config): suppress gosec G703 false positive in ensureDir Paths come from user-controlled env vars (XDG_*) or OS defaults; path traversal is not a concern for a CLI tool running as the invoking user.
Summary
pkg/command/background.go) and daemon PID file (pkg/daemon/agent/daemon.go) fromos.TempDir()toPathManager.ProcessLockFile(),ProcessPIDFile(),ProcessStreamsFile(), andDaemonPIDFile()GetDevsyKeysDir()inpkg/ssh/keys.gofrom returningstringto(string, error), usingPathManager.SSHKeysDir()instead of manual home-dir fallback logic. Updated all callers (GetDevsyHostKey,GetDevsyPublicKey,GetDevsyPrivateKeyRaw)/tmpandos.TempDir()in SSH agent socket setup (pkg/ssh/server/agent.go) withPathManager.RuntimeDir()pkg/dockercredentials/helper.go) fromos.TempDir()toPathManager.LogDir()/tmp/pprof_portsincmd/profile.gowithPathManager.StateDir()+pprof_ports