From 9a1543caec75a7b02dd2ec9a1111756bb1716454 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Tue, 30 Jun 2020 17:21:52 -0400 Subject: Add --tz flag to create, run --tz flag sets timezone inside container Can be set to IANA timezone as well as `local` to match host machine Signed-off-by: Ashley Cui --- libpod/options.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libpod/options.go') diff --git a/libpod/options.go b/libpod/options.go index 4041fb1cf..83d2c2e1f 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1525,6 +1525,30 @@ func withSetAnon() VolumeCreateOption { } } +// WithTimezone sets the timezone in the container +func WithTimezone(path string) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return define.ErrCtrFinalized + } + if path != "local" { + zone := filepath.Join("/usr/share/zoneinfo", path) + + file, err := os.Stat(zone) + if err != nil { + return err + } + //We don't want to mount a timezone directory + if file.IsDir() { + return errors.New("Invalid timezone: is a directory") + } + } + + ctr.config.Timezone = path + return nil + } +} + // Pod Creation Options // WithPodName sets the name of the pod. -- cgit v1.2.3-54-g00ecf