mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-02-04 10:26:01 -05:00
fix timezone fetching on macOS High Sierra
This commit is contained in:
parent
97d831e054
commit
f720f6acd4
@ -43,9 +43,12 @@ use tokio_signal::unix::{Signal, SIGINT, SIGTERM};
|
|||||||
use web;
|
use web;
|
||||||
|
|
||||||
// These are used in a hack to get the name of the current time zone (e.g. America/Los_Angeles).
|
// These are used in a hack to get the name of the current time zone (e.g. America/Los_Angeles).
|
||||||
// They seem to be correct for Linux and OS X at least.
|
// They seem to be correct for Linux and macOS at least.
|
||||||
const LOCALTIME_PATH: &'static str = "/etc/localtime";
|
const LOCALTIME_PATH: &'static str = "/etc/localtime";
|
||||||
const ZONEINFO_PATH: &'static str = "/usr/share/zoneinfo/";
|
const ZONEINFO_PATHS: [&'static str; 2] = [
|
||||||
|
"/usr/share/zoneinfo/", // Linux, macOS < High Sierra
|
||||||
|
"/var/db/timezone/zoneinfo/" // macOS High Sierra
|
||||||
|
];
|
||||||
|
|
||||||
const USAGE: &'static str = r#"
|
const USAGE: &'static str = r#"
|
||||||
Usage: moonfire-nvr run [options]
|
Usage: moonfire-nvr run [options]
|
||||||
@ -86,11 +89,12 @@ fn setup_shutdown_future(h: &reactor::Handle) -> Box<Future<Item = (), Error = (
|
|||||||
fn resolve_zone() -> String {
|
fn resolve_zone() -> String {
|
||||||
let p = ::std::fs::read_link(LOCALTIME_PATH).expect("unable to read localtime symlink");
|
let p = ::std::fs::read_link(LOCALTIME_PATH).expect("unable to read localtime symlink");
|
||||||
let p = p.to_str().expect("localtime symlink destination must be valid UTF-8");
|
let p = p.to_str().expect("localtime symlink destination must be valid UTF-8");
|
||||||
if !p.starts_with(ZONEINFO_PATH) {
|
for zp in &ZONEINFO_PATHS {
|
||||||
panic!("Expected {} to point to a path within {}; actually points to {}",
|
if p.starts_with(zp) {
|
||||||
LOCALTIME_PATH, ZONEINFO_PATH, p);
|
return p[zp.len()..].into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p[ZONEINFO_PATH.len()..].into()
|
panic!("{} points to unexpected path {}", LOCALTIME_PATH, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Syncer {
|
struct Syncer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user