From 45154dcc7ea4f250044f858b1ae469fe608e636b Mon Sep 17 00:00:00 2001 From: "Jason T. Greene" Date: Thu, 29 Sep 2022 15:20:18 -0500 Subject: [PATCH] Fix Windows regression introduced by PR #1161 Before 50eb74a4b1156bd this code used unshare.IsRootless() which on Windows always returns false (the behavior we want). After 50eb74a4b1156bd, a condition was unintentionally inverted, allowing Windows to function. Commit 18803495e871 fixed the inversion, but unintentionally excluded Windows since it used == 0 instead of <= 0 (Windows returns -1) Move the logic behind a function with a comment since the Windows path is a bit exotic. In the future, the Windows path should likely be refactored to be more intuitive; however, this will get things working for now. Signed-off-by: Jason T. Greene --- common/pkg/config/default.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/pkg/config/default.go b/common/pkg/config/default.go index eb3f5fb1e4..c5fca7f0c4 100644 --- a/common/pkg/config/default.go +++ b/common/pkg/config/default.go @@ -180,7 +180,7 @@ func DefaultConfig() (*Config, error) { } defaultEngineConfig.SignaturePolicyPath = DefaultSignaturePolicyPath - if unshare.GetRootlessUID() > 0 { + if useUserConfigLocations() { configHome, err := homedir.GetConfigHome() if err != nil { return nil, err @@ -289,7 +289,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) { return nil, err } } - storeOpts, err := types.DefaultStoreOptions(unshare.GetRootlessUID() > 0, unshare.GetRootlessUID()) + storeOpts, err := types.DefaultStoreOptions(useUserConfigLocations(), unshare.GetRootlessUID()) if err != nil { return nil, err } @@ -427,7 +427,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) { } func defaultTmpDir() (string, error) { - if unshare.GetRootlessUID() == 0 { + if !useUserConfigLocations() { return getLibpodTmpDir(), nil } @@ -679,3 +679,10 @@ func getDefaultSSHConfig() string { dirname := homedir.Get() return filepath.Join(dirname, ".ssh", "config") } + +func useUserConfigLocations() bool { + // NOTE: For now we want Windows to use system locations. + // GetRootlessUID == -1 on Windows, so exclude negative range + return unshare.GetRootlessUID() > 0 +} +