diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-09-21 22:46:31 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-09-21 22:46:31 +0200 |
commit | e6cdd37bc0dcce6f94d9b9810dfd65f7c27331eb (patch) | |
tree | 0b3bc51b67ccd15ddab798d7a36de43125232051 | |
parent | 1fb4c47ec521542f2cc13a92ce97b74031740bb0 (diff) | |
download | mailremind-e6cdd37bc0dcce6f94d9b9810dfd65f7c27331eb.tar.gz mailremind-e6cdd37bc0dcce6f94d9b9810dfd65f7c27331eb.tar.bz2 mailremind-e6cdd37bc0dcce6f94d9b9810dfd65f7c27331eb.zip |
Searching for time locations in other directories.
-rw-r--r-- | timelocs.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/timelocs.go b/timelocs.go index bb04070..10b0f33 100644 --- a/timelocs.go +++ b/timelocs.go @@ -3,16 +3,59 @@ package main import ( "archive/zip" "log" + "os" "path" "runtime" "sort" "sync" + "time" ) var timeLocs []string var tlOnce sync.Once +func findfiles(p, prefix string, files []string) []string { + d, err := os.Open(p) + if err != nil { + return files + } + defer d.Close() + + infos, err := d.Readdir(-1) + if err != nil { + return files + } + + for _, info := range infos { + if info.Mode().IsRegular() { + files = append(files, prefix+info.Name()) + } else if info.IsDir() { + files = findfiles(path.Join(p, info.Name()), info.Name()+"/", files) + } + } + + return files +} + func listTimeLocations() ([]string, error) { + for _, p := range []string{"/usr/share/zoneinfo", "/usr/share/lib/zoneinfo", "/usr/lib/locale/TZ"} { + files := findfiles(p, "", nil) + duprem := make(map[string]bool) + for _, loc := range files { + if _, err := time.LoadLocation(loc); err == nil { + duprem[loc] = true + } + } + var locs []string + for loc := range duprem { + locs = append(locs, loc) + } + if len(locs) > 0 { + sort.Strings(locs) + return locs, nil + } + } + zoneinfoZip := path.Join(runtime.GOROOT(), "lib", "time", "zoneinfo.zip") z, err := zip.OpenReader(zoneinfoZip) if err != nil { |