spiegel_podman/libpod/container_stat_linux.go
Nalin Dahyabhai 61195895f3 Pass context.Context values down to newer buildah APIs
Buildah added some variants of APIs that should improve support for
cancellation, so let's use them.

Remove the import alias for its copier package in
cmd/podman/containers/cp.go and libpod/container_copy_common.go to be
more friendly to grep.

Update the "prune leftover build containers" test to intentionally leave
some behind during its setup instead of SIGKILLing a build process.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2026-09-29 06:05:20 -04:00

42 lines
1.3 KiB
Go

//go:build !remote
package libpod
import (
"context"
"go.podman.io/buildah/copier"
"go.podman.io/podman/v6/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(ctx context.Context, 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(ctx, 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(ctx context.Context, 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(ctx, containerPath)
}
// If the container is NOT running, we need to resolve the path
// on the host.
return c.statOnHost(ctx, mountPoint, containerPath)
}