From 98384ff1caa44ab32c6aca86d2599dc28d254cc6 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 3 May 2021 14:53:34 -0400 Subject: [PATCH] Expand Variables on rootlessStoragePath The current code was hanging for me, this makes sure the path is expanded properly when it is read. Fixes: https://github.com/containers/podman/issues/10181 Signed-off-by: Daniel J Walsh --- types/options.go | 5 ++++- types/options_test.go | 13 +++++++++++++ types/utils.go | 3 +-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/types/options.go b/types/options.go index fb80b18c51..223db8f00f 100644 --- a/types/options.go +++ b/types/options.go @@ -172,7 +172,10 @@ func getRootlessStorageOpts(rootlessUID int, systemOpts StoreOptions) (StoreOpti } opts.RunRoot = rootlessRuntime if systemOpts.RootlessStoragePath != "" { - opts.GraphRoot = systemOpts.RootlessStoragePath + opts.GraphRoot, err = expandEnvPath(systemOpts.RootlessStoragePath, rootlessUID) + if err != nil { + return opts, err + } } else { opts.GraphRoot = filepath.Join(dataDir, "containers", "storage") } diff --git a/types/options_test.go b/types/options_test.go index 2ee285671d..be12ae6762 100644 --- a/types/options_test.go +++ b/types/options_test.go @@ -3,6 +3,7 @@ package types import ( "fmt" "os" + "path/filepath" "testing" "gotest.tools/assert" @@ -97,3 +98,15 @@ func TestGetRootlessStorageOpts(t *testing.T) { os.Unsetenv("STORAGE_DRIVER") } } + +func TestGetRootlessStorageOpts2(t *testing.T) { + opts := StoreOptions{ + RootlessStoragePath: "/$HOME/$UID/containers/storage", + } + storageOpts, err := getRootlessStorageOpts(2000, opts) + + expectedPath := filepath.Join(os.Getenv("HOME"), "2000", "containers/storage") + + assert.NilError(t, err) + assert.Equal(t, storageOpts.GraphRoot, expectedPath) +} diff --git a/types/utils.go b/types/utils.go index f64bbe8598..d2dca7b684 100644 --- a/types/utils.go +++ b/types/utils.go @@ -156,8 +156,7 @@ func getRootlessUID() int { func expandEnvPath(path string, rootlessUID int) (string, error) { path = strings.Replace(path, "$UID", strconv.Itoa(rootlessUID), -1) - path = os.ExpandEnv(path) - return path, nil + return filepath.Clean(os.ExpandEnv(path)), nil } func DefaultConfigFile(rootless bool) (string, error) {