Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/systemd/quadlet/unitdirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"go.podman.io/podman/v6/pkg/logiface"
"go.podman.io/podman/v6/pkg/util"
)

// This returns whether a file has an extension recognized as a valid Quadlet unit type.
Expand Down Expand Up @@ -230,6 +231,12 @@ func getRootlessDirs(paths *searchPaths, nonNumericFilter, userLevelFilter func(
}

configDir, err := os.UserConfigDir()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't Quadlet just call util.GetRootlessConfigHomeDir with the new addition? All these checks seem duplicated

if os.Getenv("XDG_CONFIG_HOME") == "" {
home, found := os.LookupEnv("HOME")
if !found || home == "" || home == string(os.PathSeparator) {
configDir, err = util.GetRootlessConfigHomeDir()
}
}
if err != nil {
logiface.Errorf("Warning: %v", err)
return
Expand Down
22 changes: 22 additions & 0 deletions pkg/util/utils_linux_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
package util

import (
"os/user"
"path/filepath"
"testing"
)

func TestGetRootlessConfigHomeDirWithRootHome(t *testing.T) {
u, err := user.Current()
if err != nil {
t.Fatal(err)
}

t.Setenv("XDG_CONFIG_HOME", "")
t.Setenv("HOME", "/")

configDir, err := GetRootlessConfigHomeDir()
if err != nil {
t.Fatal(err)
}

expected := filepath.Join(u.HomeDir, ".config")
if configDir != expected {
t.Fatalf("expected %q, got %q", expected, configDir)
}
}

func TestIsVirtualConsoleDevice(t *testing.T) {
testcases := []struct {
expectedResult bool
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/utils_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ package util
// should work to take darwin from this

import (
"os"
"os/user"
"path/filepath"
"strconv"

"go.podman.io/podman/v6/pkg/rootless"
"go.podman.io/storage/pkg/homedir"
Expand All @@ -22,6 +25,13 @@ func GetRootlessRuntimeDir() (string, error) {

// GetRootlessConfigHomeDir returns the config home directory when running as non root
func GetRootlessConfigHomeDir() (string, error) {
if os.Getenv("XDG_CONFIG_HOME") == "" && os.Getenv("HOME") == string(os.PathSeparator) {
u, err := user.LookupId(strconv.Itoa(rootless.GetRootlessUID()))
if err == nil && u.HomeDir != "" {
return filepath.Join(u.HomeDir, ".config"), nil
}
}

return homedir.GetConfigHome()
}

Expand Down
Loading