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>
This commit is contained in:
Doug Rabson committed 2022-09-05 10:20:50 +01:00
1 parent 7a1abd03c5
commit a3aecf0f26
3 files changed
+20 -3

No files matched your search

+1 -3
View File
@@ -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) {
+9
View File
@@ -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
}
+10
View File
@@ -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
}