Skip to content

Commit

Permalink
Merge pull request #887 from rhatdan/rootless
Browse files Browse the repository at this point in the history
Expand Variables on rootlessStoragePath
  • Loading branch information
rhatdan authored May 6, 2021
2 parents 0072fc4 + 98384ff commit b2a44b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
13 changes: 13 additions & 0 deletions types/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"fmt"
"os"
"path/filepath"
"testing"

"gotest.tools/assert"
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b2a44b0

Please sign in to comment.