summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-08-27 16:34:57 +0100
committerDoug Rabson <dfr@rabson.org>2022-09-05 10:20:50 +0100
commita3aecf0f26971cbf178fc705d0983ee248a6492b (patch)
treef38267d25b040c27a63733e0d4847f53c18150bd /libpod
parent7a1abd03c54791186216f6086c58f0f87c7e4f46 (diff)
downloadpodman-a3aecf0f26971cbf178fc705d0983ee248a6492b.tar.gz
podman-a3aecf0f26971cbf178fc705d0983ee248a6492b.tar.bz2
podman-a3aecf0f26971cbf178fc705d0983ee248a6492b.zip
libpod: Factor out setting volume atime to container_internal_linux.go
It turns out that field names in syscall.Stat_t are platform-specific. An alternative to this could change fixVolumePermissions to use unix.Lstat since unix.Stat_t uses the same mmember name for Atim on both Linux and FreeBSD. [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_common.go4
-rw-r--r--libpod/container_internal_freebsd.go9
-rw-r--r--libpod/container_internal_linux.go10
3 files changed, 20 insertions, 3 deletions
diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go
index cb3c602af..192a86b6a 100644
--- a/libpod/container_internal_common.go
+++ b/libpod/container_internal_common.go
@@ -2654,9 +2654,7 @@ func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
if err := os.Chmod(mountPoint, st.Mode()); err != nil {
return err
}
- stat := st.Sys().(*syscall.Stat_t)
- atime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
- if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
+ if err := setVolumeAtime(mountPoint, st); err != nil {
return err
}
} else if !os.IsNotExist(err) {
diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go
index c87617848..40c6c5ebf 100644
--- a/libpod/container_internal_freebsd.go
+++ b/libpod/container_internal_freebsd.go
@@ -274,3 +274,12 @@ func (c *Container) isSlirp4netnsIPv6() (bool, error) {
func (c *Container) hasNetNone() bool {
return c.state.NetworkJail == ""
}
+
+func setVolumeAtime(mountPoint string, st os.FileInfo) error {
+ stat := st.Sys().(*syscall.Stat_t)
+ atime := time.Unix(int64(stat.Atimespec.Sec), int64(stat.Atimespec.Nsec)) //nolint: unconvert
+ if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index ad04ef26c..83882ecac 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -11,6 +11,7 @@ import (
"strings"
"sync"
"syscall"
+ "time"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containers/common/libnetwork/types"
@@ -634,3 +635,12 @@ func (c *Container) hasNetNone() bool {
}
return false
}
+
+func setVolumeAtime(mountPoint string, st os.FileInfo) error {
+ stat := st.Sys().(*syscall.Stat_t)
+ atime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
+ if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
+ return err
+ }
+ return nil
+}