Skip to content

Commit

Permalink
[#928] Reset to a proper dir when TZDIR env var is "internal" or "macOS"
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Nov 7, 2020
1 parent 7d9b16d commit 4c8428b
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@
## it's in "/usr/share/zoneinfo" where CCTZ looks by default. On some systems
## (solaris, osx) it might be in a different location. So, help ourselves by
## setting the TZDIR env var, but only if it's not already set.
if (Sys.getenv("TZDIR") == "") {
## adapted from OlsonNames function
tzdir <-
if (.Platform$OS.type == "windows") {
file.path(R.home("share"), "zoneinfo")
} else if (!file.exists("/usr/share/zoneinfo")) {
tzdirs <- c(file.path(R.home("share"), "zoneinfo"),
"/usr/share/lib/zoneinfo", "/usr/lib/zoneinfo",
"/usr/local/etc/zoneinfo", "/etc/zoneinfo",
"/usr/etc/zoneinfo")
tzdirs <- tzdirs[file.exists(tzdirs)]
if (length(tzdirs)) tzdirs[[1]]
else NULL
}
if (!is.null(tzdir)) {
Sys.setenv(TZDIR = tzdir)

## adapted from Syz.timezone and OlsonNames function
.find_tzdir <- function() {
if (.Platform$OS.type == "windows")
return(file.path(R.home("share"), "zoneinfo"))
tzdirs <- c("/usr/share/zoneinfo",
"/usr/share/lib/zoneinfo",
"/usr/lib/zoneinfo",
"/usr/local/etc/zoneinfo",
"/etc/zoneinfo",
"/usr/etc/zoneinfo",
"/usr/share/zoneinfo.default",
"/var/db/timezone/zoneinfo",
file.path(R.home("share"), "zoneinfo"))
tzdirs <- tzdirs[file.exists(tzdirs)]
if (length(tzdirs)) tzdirs[[1]]
else NULL
}

tzdir <- Sys.getenv("TZDIR")
if (tzdir == "internal") {
Sys.setenv(TZDIR = file.path(R.home("share"), "zoneinfo"))
} else if (tzdir == "macOS") {
if (!is.null(dir <- .find_tzdir()))
Sys.setenv(TZDIR = dir)
} else if (tzdir == "") {
# not checking for /usr/share/zoneinfo which is the default in CCTZ
if (!file.exists("/usr/share/zoneinfo")) {
if (!is.null(dir <- .find_tzdir()))
Sys.setenv(TZDIR = dir)
}
}

Expand Down

0 comments on commit 4c8428b

Please sign in to comment.