88 "errors"
99 "fmt"
1010 "io"
11- "io/fs"
1211 "os"
1312 "path/filepath"
1413 "strconv"
@@ -25,6 +24,7 @@ import (
2524 "github.com/containers/common/pkg/config"
2625 "github.com/containers/common/pkg/hooks"
2726 "github.com/containers/common/pkg/hooks/exec"
27+ "github.com/containers/common/pkg/timezone"
2828 cutil "github.com/containers/common/pkg/util"
2929 "github.com/containers/podman/v4/libpod/define"
3030 "github.com/containers/podman/v4/libpod/events"
@@ -1706,45 +1706,18 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
17061706 }
17071707
17081708 tz := c .Timezone ()
1709- if tz != "" {
1710- timezonePath := filepath .Join ("/usr/share/zoneinfo" , tz )
1711- if tz == "local" {
1712- timezonePath , err = filepath .EvalSymlinks ("/etc/localtime" )
1713- if err != nil {
1714- return "" , fmt .Errorf ("finding local timezone for container %s: %w" , c .ID (), err )
1715- }
1716- }
1717- // make sure to remove any existing localtime file in the container to not create invalid links
1718- err = unix .Unlinkat (etcInTheContainerFd , "localtime" , 0 )
1719- if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
1720- return "" , fmt .Errorf ("removing /etc/localtime: %w" , err )
1721- }
1722-
1723- hostPath , err := securejoin .SecureJoin (mountPoint , timezonePath )
1724- if err != nil {
1725- return "" , fmt .Errorf ("resolve zoneinfo path in the container: %w" , err )
1709+ localTimePath , err := timezone .ConfigureContainerTimeZone (tz , c .state .RunDir , mountPoint , etcInTheContainerPath , c .ID ())
1710+ if err != nil {
1711+ return "" , fmt .Errorf ("configuring timezone for container %s: %w" , c .ID (), err )
1712+ }
1713+ if localTimePath != "" {
1714+ if err := c .relabel (localTimePath , c .config .MountLabel , false ); err != nil {
1715+ return "" , err
17261716 }
1727-
1728- _ , err = os .Stat (hostPath )
1729- if err != nil {
1730- // file does not exists which means tzdata is not installed in the container, just create /etc/locatime which a copy from the host
1731- logrus .Debugf ("Timezone %s does not exist in the container, create our own copy from the host" , timezonePath )
1732- localtimePath , err := c .copyTimezoneFile (timezonePath )
1733- if err != nil {
1734- return "" , fmt .Errorf ("setting timezone for container %s: %w" , c .ID (), err )
1735- }
1736- if c .state .BindMounts == nil {
1737- c .state .BindMounts = make (map [string ]string )
1738- }
1739- c .state .BindMounts ["/etc/localtime" ] = localtimePath
1740- } else {
1741- // file exists lets just symlink according to localtime(5)
1742- logrus .Debugf ("Create locatime symlink for %s" , timezonePath )
1743- err = unix .Symlinkat (".." + timezonePath , etcInTheContainerFd , "localtime" )
1744- if err != nil {
1745- return "" , fmt .Errorf ("creating /etc/localtime symlink: %w" , err )
1746- }
1717+ if c .state .BindMounts == nil {
1718+ c .state .BindMounts = make (map [string ]string )
17471719 }
1720+ c .state .BindMounts ["/etc/localtime" ] = localTimePath
17481721 }
17491722
17501723 // Request a mount of all named volumes
0 commit comments