From 9f1871f0f8e42e13ecedc5f489cdcc0bffe6fe44 Mon Sep 17 00:00:00 2001 From: Gabi Beyer Date: Mon, 24 Jun 2019 23:31:56 +0000 Subject: [PATCH] cli: update ctrsMapTreePath to allow rootless dir 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/katautils/oci.go b/pkg/katautils/oci.go index 0eb80d5846..f8b4574c1d 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,14 @@ func FetchContainerIDMapping(containerID string) (string, error) { return "", fmt.Errorf("Missing container ID") } + if rootless.IsRootless() { + path, err := rootless.GetRootlessRuntimeDir() + if err != nil { + return "", err + } + SetCtrsMapTreePath(path) + } + dirPath := filepath.Join(ctrsMapTreePath, containerID) files, err := ioutil.ReadDir(dirPath) @@ -62,6 +72,13 @@ func AddContainerIDMapping(ctx context.Context, containerID, sandboxID string) e return fmt.Errorf("Missing sandbox ID") } + if rootless.IsRootless() { + path, err := rootless.GetRootlessRuntimeDir() + if err != nil { + return err + } + SetCtrsMapTreePath(path) + } parentPath := filepath.Join(ctrsMapTreePath, containerID) if err := os.RemoveAll(parentPath); err != nil { @@ -86,6 +103,13 @@ func DelContainerIDMapping(ctx context.Context, containerID string) error { return fmt.Errorf("Missing container ID") } + if rootless.IsRootless() { + path, err := rootless.GetRootlessRuntimeDir() + if err != nil { + return err + } + SetCtrsMapTreePath(path) + } path := filepath.Join(ctrsMapTreePath, containerID) return os.RemoveAll(path)