Merge branch 'master' into new-schema

This commit is contained in:
Scott Lamb
2020-11-22 20:40:16 -08:00
13 changed files with 118 additions and 64 deletions

View File

@@ -53,11 +53,17 @@ enum OpenMode {
/// Locks the directory without opening the database.
/// The returned `dir::Fd` holds the lock and should be kept open as long as the `Connection` is.
fn open_dir(db_dir: &Path, mode: OpenMode) -> Result<dir::Fd, Error> {
let dir = dir::Fd::open(db_dir, mode == OpenMode::Create)?;
let dir = dir::Fd::open(db_dir, mode == OpenMode::Create)
.map_err(|e| e.context(if e == nix::Error::Sys(nix::errno::Errno::ENOENT) {
format!("db dir {} not found; try running moonfire-nvr init",
db_dir.display())
} else {
format!("unable to open db dir {}: {}", db_dir.display(), &e)
}))?;
let ro = mode == OpenMode::ReadOnly;
dir.lock(if ro { FlockArg::LockSharedNonblock } else { FlockArg::LockExclusiveNonblock })
.map_err(|e| e.context(format!("db dir {:?} already in use; can't get {} lock",
db_dir, if ro { "shared" } else { "exclusive" })))?;
.map_err(|e| e.context(format!("db dir {} already in use; can't get {} lock",
db_dir.display(), if ro { "shared" } else { "exclusive" })))?;
Ok(dir)
}

View File

@@ -54,7 +54,7 @@ pub struct Args {
db_dir: PathBuf,
/// Directory holding user interface files (.html, .js, etc).
#[structopt(default_value = "/usr/local/lib/moonfire-nvr/ui", value_name="path",
#[structopt(long, default_value = "/usr/local/lib/moonfire-nvr/ui", value_name="path",
parse(from_os_str))]
ui_dir: std::path::PathBuf,

View File

@@ -110,7 +110,7 @@ pub struct Stream<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(serialize_with = "Stream::serialize_days")]
pub days: Option<&'a BTreeMap<db::StreamDayKey, db::StreamDayValue>>,
pub days: Option<BTreeMap<db::StreamDayKey, db::StreamDayValue>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub config: Option<StreamConfig<'a>>,
@@ -219,7 +219,7 @@ impl<'a> Camera<'a> {
})
}
fn serialize_streams<S>(streams: &[Option<Stream<'a>>; 2], serializer: S) -> Result<S::Ok, S::Error>
fn serialize_streams<S>(streams: &[Option<Stream>; 2], serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer {
let mut map = serializer.serialize_map(Some(streams.len()))?;
for (i, s) in streams.iter().enumerate() {
@@ -247,7 +247,7 @@ impl<'a> Stream<'a> {
total_duration_90k: s.duration.0,
total_sample_file_bytes: s.sample_file_bytes,
fs_bytes: s.fs_bytes,
days: if include_days { Some(&s.days) } else { None },
days: if include_days { Some(s.days()) } else { None },
config: match include_config {
false => None,
true => Some(StreamConfig {
@@ -257,10 +257,10 @@ impl<'a> Stream<'a> {
}))
}
fn serialize_days<S>(days: &Option<&BTreeMap<db::StreamDayKey, db::StreamDayValue>>,
fn serialize_days<S>(days: &Option<BTreeMap<db::StreamDayKey, db::StreamDayValue>>,
serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer {
let days = match *days {
let days = match days.as_ref() {
Some(d) => d,
None => return serializer.serialize_none(),
};