Repository navigation
fix(config): respect $HOME when resolving the default storage directory - #704
NopeCharon wants to merge 2 commits into
Conversation
|
Thanks for the fix, the change looks good to me. The Lint failure isn't from this PR. golangci-lint v2.4 panics on the Go 1.26 runner, and that was fixed on main in #716. Could you rebase so CI goes green? One thing worth a line in the release notes: when nit: |
config.NewRoot resolved the default storage and log directories through os/user.Current. With cgo enabled (as in the release builds) that queries the user database via getpwuid_r and ignores the $HOME environment variable, so overriding $HOME, for example in tests or sandboxed environments, still created ~/.modctl under the system home directory. This was observed on aarch64-darwin, where every command, including `modctl version`, touched the real home directory. Resolve the home directory with os.UserHomeDir instead, which honors $HOME (%USERPROFILE% on Windows), and fall back to os/user.Current only when the environment variable is unset so that environments without $HOME keep working as before. Add unit tests for both the $HOME override and the fallback path. Fixes modelpack#580 Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
|
Rebased onto main and added a t.Skip in TestNewRootFallsBackToCurrentUser when user.Current() fails. I left the release note to you since there's no changelog in this PR. |
a5a7090 to
dd8ea8c
Compare
Problem
config.NewRoot()resolves the default--storage-dirand--log-dirthroughos/user.Current(). With cgo enabled (as in the release builds), that queries the user database viagetpwuid_rand ignores$HOME. As a result, every command, includingmodctl version, creates~/.modctlunder the system home directory even when$HOMEpoints somewhere else, for example a temporary directory in tests or a sandbox.Fixes #580
Fix
os.UserHomeDir(), which honors$HOME(%USERPROFILE%on Windows).os/user.Current()only when the environment variable is unset. Environments without$HOME(some service managers or minimal containers) keep working as before instead of failing at startup.Tests
pkg/config/root_test.go:TestNewRootRespectsHomeEnvsets$HOMEto a temp dir and checksStorageDir/LogDir. It fails onmain(it resolves to the real home directory) and passes with this change.TestNewRootFallsBackToCurrentUserclears$HOMEand checks theos/userfallback.go test -tags static,system_libgit2 ./pkg/config ./cmdpasses.golangci-lint run(v2.4) reports 0 issues.HOME=/tmp/fakehome modctl versionnow creates/tmp/fakehome/.modctl.