mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
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:
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user