diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-05 03:57:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-05 03:57:17 -0500 |
commit | 05080a12a998802570ee123a39368a0fe97e2fd2 (patch) | |
tree | e2828a62966c6d05e2d79cb7cc90ae3254279657 /libpod/container_path_resolution.go | |
parent | 4e5cc6a3a61d9d2f1d3b97fc10684ec5617816ab (diff) | |
parent | a090301bbb10424ce4f99e40c97959f0e8664718 (diff) | |
download | podman-05080a12a998802570ee123a39368a0fe97e2fd2.tar.gz podman-05080a12a998802570ee123a39368a0fe97e2fd2.tar.bz2 podman-05080a12a998802570ee123a39368a0fe97e2fd2.zip |
Merge pull request #9593 from vrothberg/cp-tmp
podman cp: support copying on tmpfs mounts
Diffstat (limited to 'libpod/container_path_resolution.go')
-rw-r--r-- | libpod/container_path_resolution.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libpod/container_path_resolution.go b/libpod/container_path_resolution.go index 5245314ae..d798963b1 100644 --- a/libpod/container_path_resolution.go +++ b/libpod/container_path_resolution.go @@ -1,3 +1,4 @@ +// +linux package libpod import ( @@ -10,6 +11,19 @@ import ( "github.com/sirupsen/logrus" ) +// pathAbs returns an absolute path. If the specified path is +// relative, it will be resolved relative to the container's working dir. +func (c *Container) pathAbs(path string) string { + if !filepath.IsAbs(path) { + // If the containerPath is not absolute, it's relative to the + // container's working dir. To be extra careful, let's first + // join the working dir with "/", and the add the containerPath + // to it. + path = filepath.Join(filepath.Join("/", c.WorkingDir()), path) + } + return path +} + // resolveContainerPaths resolves the container's mount point and the container // path as specified by the user. Both may resolve to paths outside of the // container's mount point when the container path hits a volume or bind mount. @@ -20,14 +34,7 @@ import ( // the host). func (c *Container) resolvePath(mountPoint string, containerPath string) (string, string, error) { // Let's first make sure we have a path relative to the mount point. - pathRelativeToContainerMountPoint := containerPath - if !filepath.IsAbs(containerPath) { - // If the containerPath is not absolute, it's relative to the - // container's working dir. To be extra careful, let's first - // join the working dir with "/", and the add the containerPath - // to it. - pathRelativeToContainerMountPoint = filepath.Join(filepath.Join("/", c.WorkingDir()), containerPath) - } + pathRelativeToContainerMountPoint := c.pathAbs(containerPath) resolvedPathOnTheContainerMountPoint := filepath.Join(mountPoint, pathRelativeToContainerMountPoint) pathRelativeToContainerMountPoint = strings.TrimPrefix(pathRelativeToContainerMountPoint, mountPoint) pathRelativeToContainerMountPoint = filepath.Join("/", pathRelativeToContainerMountPoint) |