From 6047102cfb0ff162542e5e32a8c65dbd72779a04 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Mon, 25 Nov 2019 15:52:46 +0800 Subject: [PATCH] timeutil: do not use system files to verify timezone (#13593) --- util/timeutil/time.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/util/timeutil/time.go b/util/timeutil/time.go index fba901f439bd7..b11b1dd5d127f 100644 --- a/util/timeutil/time.go +++ b/util/timeutil/time.go @@ -15,7 +15,6 @@ package timeutil import ( "fmt" - "os" "path/filepath" "strings" "sync" @@ -41,13 +40,6 @@ var locCa *locCache // systemTZ is current TiDB's system timezone name. var systemTZ string -var zoneSources = []string{ - "/usr/share/zoneinfo/", - "/usr/share/lib/zoneinfo/", - "/usr/lib/locale/TZ/", - // this is for macOS - "/var/db/timezone/zoneinfo/", -} // locCache is a simple map with lock. It stores all used timezone during the lifetime of tidb instance. // Talked with Golang team about whether they can have some forms of cache policy available for programmer, @@ -60,7 +52,7 @@ type locCache struct { } // InferSystemTZ reads system timezone from `TZ`, the path of the soft link of `/etc/localtime`. If both of them are failed, system timezone will be set to `UTC`. -// It is exported because we need to use it during bootstap stage. And it should be only used at that stage. +// It is exported because we need to use it during bootstrap stage. And it should be only used at that stage. func InferSystemTZ() string { // consult $TZ to find the time zone to use. // no $TZ means use the system default /etc/localtime. @@ -79,10 +71,9 @@ func InferSystemTZ() string { } logutil.BgLogger().Error("locate timezone files failed", zap.Error(err1)) case tz != "" && tz != "UTC": - for _, source := range zoneSources { - if _, err := os.Stat(source + tz); err == nil { - return tz - } + _, err := time.LoadLocation(tz) + if err == nil { + return tz } } return "UTC" @@ -161,8 +152,8 @@ func LoadLocation(name string) (*time.Location, error) { func Zone(loc *time.Location) (string, int64) { _, offset := time.Now().In(loc).Zone() name := loc.String() - // when we found name is "System", we have no chice but push down - // "System" to tikv side. + // when we found name is "System", we have no choice but push down + // "System" to TiKV side. if name == "Local" { name = "System" }