From 020051d3eaa9408ad41193edae789ec50a60cde2 Mon Sep 17 00:00:00 2001 From: Gabi Beyer Date: Thu, 27 Jun 2019 21:50:01 +0000 Subject: [PATCH] cli: update paths to be configurable for rootless execution Before using the default ctrsMapTrePath, check whether the runtime is being ran rootlessly, and if so set the ctrsMapTreePath to the rootlessRuntimeDir configured by the libpod rootless library. Fixes: #1358 Signed-off-by: Gabi Beyer --- pkg/katautils/oci.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/katautils/oci.go b/pkg/katautils/oci.go index 0eb80d5846..ed889d4948 100644 --- a/pkg/katautils/oci.go +++ b/pkg/katautils/oci.go @@ -11,6 +11,8 @@ import ( "io/ioutil" "os" "path/filepath" + + "github.com/kata-containers/runtime/pkg/rootless" ) const ctrsMappingDirMode = os.FileMode(0750) @@ -31,6 +33,10 @@ func FetchContainerIDMapping(containerID string) (string, error) { return "", fmt.Errorf("Missing container ID") } + if rootless.IsRootless() { + SetCtrsMapTreePath(filepath.Join(rootless.GetRootlessDir(), ctrsMapTreePath)) + } + dirPath := filepath.Join(ctrsMapTreePath, containerID) files, err := ioutil.ReadDir(dirPath) @@ -62,6 +68,9 @@ func AddContainerIDMapping(ctx context.Context, containerID, sandboxID string) e return fmt.Errorf("Missing sandbox ID") } + if rootless.IsRootless() { + SetCtrsMapTreePath(filepath.Join(rootless.GetRootlessDir(), ctrsMapTreePath)) + } parentPath := filepath.Join(ctrsMapTreePath, containerID) if err := os.RemoveAll(parentPath); err != nil { @@ -86,6 +95,9 @@ func DelContainerIDMapping(ctx context.Context, containerID string) error { return fmt.Errorf("Missing container ID") } + if rootless.IsRootless() { + SetCtrsMapTreePath(filepath.Join(rootless.GetRootlessDir(), ctrsMapTreePath)) + } path := filepath.Join(ctrsMapTreePath, containerID) return os.RemoveAll(path)