aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-08-25 08:23:54 +0100
committerDoug Rabson <dfr@rabson.org>2022-09-20 08:36:23 +0100
commit75d6e7bae5abb73fb248a6c4766ab799a030cb93 (patch)
treee31bdb011ef2d626f3e0821ed35bb45c3f0d9b7c
parent0b02d4cee6e3edd8a98ebe584f03169120ef5be4 (diff)
downloadpodman-75d6e7bae5abb73fb248a6c4766ab799a030cb93.tar.gz
podman-75d6e7bae5abb73fb248a6c4766ab799a030cb93.tar.bz2
podman-75d6e7bae5abb73fb248a6c4766ab799a030cb93.zip
libpod: Move part of (*Container).stat to container_stat_linux.go
The logic that treats running containers differently from stopped containers is not needed on FreeBSD where the container mounts live in a global mount namespace. [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
-rw-r--r--libpod/container_stat_common.go30
-rw-r--r--libpod/container_stat_linux.go38
2 files changed, 39 insertions, 29 deletions
diff --git a/libpod/container_stat_common.go b/libpod/container_stat_common.go
index dc3a524f5..4d6726946 100644
--- a/libpod/container_stat_common.go
+++ b/libpod/container_stat_common.go
@@ -15,25 +15,6 @@ import (
"github.com/containers/podman/v4/pkg/copy"
)
-// statInsideMount stats the specified path *inside* the container's mount and PID
-// namespace. It returns the file info along with the resolved root ("/") and
-// the resolved path (relative to the root).
-func (c *Container) statInsideMount(containerPath string) (*copier.StatForItem, string, string, error) {
- resolvedRoot := "/"
- resolvedPath := c.pathAbs(containerPath)
- var statInfo *copier.StatForItem
-
- err := c.joinMountAndExec(
- func() error {
- var statErr error
- statInfo, statErr = secureStat(resolvedRoot, resolvedPath)
- return statErr
- },
- )
-
- return statInfo, resolvedRoot, resolvedPath, err
-}
-
// statOnHost stats the specified path *on the host*. It returns the file info
// along with the resolved root and the resolved path. Both paths are absolute
// to the host's root. Note that the paths may resolved outside the
@@ -72,16 +53,7 @@ func (c *Container) stat(containerMountPoint string, containerPath string) (*def
return nil, "", "", copy.ErrENOENT
}
- if c.state.State == define.ContainerStateRunning {
- // If the container is running, we need to join it's mount namespace
- // and stat there.
- statInfo, resolvedRoot, resolvedPath, statErr = c.statInsideMount(containerPath)
- } else {
- // If the container is NOT running, we need to resolve the path
- // on the host.
- statInfo, resolvedRoot, resolvedPath, statErr = c.statOnHost(containerMountPoint, containerPath)
- }
-
+ statInfo, resolvedRoot, resolvedPath, statErr = c.statInContainer(containerMountPoint, containerPath)
if statErr != nil {
if statInfo == nil {
return nil, "", "", statErr
diff --git a/libpod/container_stat_linux.go b/libpod/container_stat_linux.go
new file mode 100644
index 000000000..5e5ef3c1a
--- /dev/null
+++ b/libpod/container_stat_linux.go
@@ -0,0 +1,38 @@
+package libpod
+
+import (
+ "github.com/containers/buildah/copier"
+ "github.com/containers/podman/v4/libpod/define"
+)
+
+// statInsideMount stats the specified path *inside* the container's mount and PID
+// namespace. It returns the file info along with the resolved root ("/") and
+// the resolved path (relative to the root).
+func (c *Container) statInsideMount(containerPath string) (*copier.StatForItem, string, string, error) {
+ resolvedRoot := "/"
+ resolvedPath := c.pathAbs(containerPath)
+ var statInfo *copier.StatForItem
+
+ err := c.joinMountAndExec(
+ func() error {
+ var statErr error
+ statInfo, statErr = secureStat(resolvedRoot, resolvedPath)
+ return statErr
+ },
+ )
+
+ return statInfo, resolvedRoot, resolvedPath, err
+}
+
+// Calls either statOnHost or statInsideMount depending on whether the
+// container is running
+func (c *Container) statInContainer(mountPoint string, containerPath string) (*copier.StatForItem, string, string, error) {
+ if c.state.State == define.ContainerStateRunning {
+ // If the container is running, we need to join it's mount namespace
+ // and stat there.
+ return c.statInsideMount(containerPath)
+ }
+ // If the container is NOT running, we need to resolve the path
+ // on the host.
+ return c.statOnHost(mountPoint, containerPath)
+}