8
8
"errors"
9
9
"fmt"
10
10
"io"
11
- "io/fs"
12
11
"os"
13
12
"path/filepath"
14
13
"strconv"
@@ -25,6 +24,7 @@ import (
25
24
"github.com/containers/common/pkg/config"
26
25
"github.com/containers/common/pkg/hooks"
27
26
"github.com/containers/common/pkg/hooks/exec"
27
+ "github.com/containers/common/pkg/timezone"
28
28
cutil "github.com/containers/common/pkg/util"
29
29
"github.com/containers/podman/v4/libpod/define"
30
30
"github.com/containers/podman/v4/libpod/events"
@@ -1706,45 +1706,18 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
1706
1706
}
1707
1707
1708
1708
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
1726
1716
}
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 )
1747
1719
}
1720
+ c .state .BindMounts ["/etc/localtime" ] = localTimePath
1748
1721
}
1749
1722
1750
1723
// Request a mount of all named volumes
0 commit comments