fix #182: error on upgrade when onvif_host empty

This commit is contained in:
Scott Lamb 2021-11-23 10:12:28 -08:00
parent af9c8bb05a
commit cf492a2ffa
2 changed files with 12 additions and 2 deletions

View File

@ -6,6 +6,11 @@ changes, see Git history.
Each release is tagged in Git and on the Docker repository
[`scottlamb/moonfire-nvr`](https://hub.docker.com/r/scottlamb/moonfire-nvr).
## unreleased
* fix [#182](https://github.com/scottlamb/moonfire-nvr/issues/182): error
on upgrade from schema 6 to schema 7 when a camera's `onvif_host` is empty.
## `v0.7.1` (2021-10-27)
* bugfix: editing a camera from `nvr config` would erroneously clear the

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception
/// Upgrades a version 6 schema to a version 7 schema.
use failure::{format_err, Error};
use failure::{format_err, Error, ResultExt};
use fnv::FnvHashMap;
use log::debug;
use rusqlite::{named_params, params};
@ -255,8 +255,13 @@ fn copy_cameras(tx: &rusqlite::Transaction) -> Result<(), Error> {
let config = CameraConfig {
description: description.take().unwrap_or_default(),
onvif_base_url: onvif_host
// Older releases set the onvif host to the empty string instead
// of using a SQL NULL, so convert empty to None here.
// https://github.com/scottlamb/moonfire-nvr/issues/182
.filter(|h| !h.is_empty())
.map(|h| Url::parse(&format!("http://{}/", h)))
.transpose()?,
.transpose()
.with_context(|_| "bad onvif_host")?,
username: username.take().unwrap_or_default(),
password: password.take().unwrap_or_default(),
..Default::default()