Skip to content

Commit

Permalink
Support system-wide containers config folder on windows
Browse files Browse the repository at this point in the history
Add %PROGRAMDATA%/containers to the list of possible
config folders.

Fixes containers/podman#22411

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
  • Loading branch information
l0rd committed Apr 29, 2024
1 parent 61ac430 commit 6c651df
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
3 changes: 0 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
)

const (
// _configPath is the path to the containers/containers.conf
// inside a given config directory.
_configPath = "containers/containers.conf"
// UserOverrideContainersConfig holds the containers config path overridden by the rootless user
UserOverrideContainersConfig = ".config/" + _configPath
// Token prefix for looking for helper binary under $BINDIR
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/containers/storage/pkg/unshare"
)

// _configPath is the path to the containers/containers.conf
// inside a given config directory.
const _configPath = "containers/containers.conf"

// userConfigPath returns the path to the users local config that is
// not shared with other users. It uses $XDG_CONFIG_HOME/containers...
// if set or $HOME/.config/containers... if not.
Expand All @@ -23,3 +27,9 @@ func userConfigPath() (string, error) {

return filepath.Join(home, UserOverrideContainersConfig), nil
}

// overrideContainersConfigPath returns the default config path overridden
// by the root user
func overrideContainersConfigPath() (string, error) {
return OverrideContainersConfig, nil
}
15 changes: 11 additions & 4 deletions pkg/config/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package config
import "os"

const (
// OverrideContainersConfig holds the default config path overridden by the root user
OverrideContainersConfig = "/etc/" + _configPath
// _configPath is the path to the containers/containers.conf
// inside a given config directory.
_configPath = "containers\\containers.conf"

// DefaultContainersConfig holds the default containers config path
DefaultContainersConfig = "/usr/share/" + _configPath
DefaultContainersConfig = ""

// DefaultSignaturePolicyPath is the default value for the
// policy.json file.
Expand All @@ -20,7 +21,13 @@ const (
// userConfigPath returns the path to the users local config that is
// not shared with other users. It uses $APPDATA/containers...
func userConfigPath() (string, error) {
return os.Getenv("APPDATA") + "\\containers\\containers.conf", nil
return os.Getenv("APPDATA") + _configPath, nil
}

// overrideContainersConfigPath returns the path to the system wide
// containers config folder. It users $PROGRAMDATA/containers...
func overrideContainersConfigPath() (string, error) {
return os.Getenv("ProgramData") + _configPath, nil
}

var defaultHelperBinariesDir = []string{
Expand Down
12 changes: 9 additions & 3 deletions pkg/config/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,22 @@ func systemConfigs() (configs []string, finalErr error) {
}
return append(configs, path), nil
}

configs = append(configs, DefaultContainersConfig)
configs = append(configs, OverrideContainersConfig)

var err error
configs, err = addConfigs(OverrideContainersConfig+".d", configs)
path, err := overrideContainersConfigPath()
if err != nil {
return nil, err
}
configs = append(configs, path)

configs, err = addConfigs(path+".d", configs)
if err != nil {
return nil, err
}

path, err := userConfigPath()
path, err = userConfigPath()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6c651df

Please sign in to comment.