update dependencies

* The mylog update fixes a couple bad bugs.
* Otherwise, just keep up with the Rust ecosystem.
This commit is contained in:
Scott Lamb 2017-06-11 12:57:55 -07:00
parent 30cda85a2e
commit bebd6ee79a
16 changed files with 474 additions and 425 deletions

797
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ bundled = ["rusqlite/bundled"]
[dependencies]
byteorder = "1.0"
docopt = "0.7"
docopt = "0.8"
futures = "0.1"
fnv = "1.0"
http-entity = { git = "https://github.com/scottlamb/http-entity", branch = "hyper-0.11.x" }
@ -25,30 +25,29 @@ libc = "0.2"
log = { version = "0.3", features = ["release_max_level_info"] }
lru-cache = "0.1"
memmap = "0.5"
mime = "0.2"
mime = "0.3"
mylog = { git = "https://github.com/scottlamb/mylog" }
openssl = "0.9"
parking_lot = { version = "0.3.8", features = [] }
parking_lot = { version = "0.4", features = [] }
reffers = { git = "https://github.com/diwic/reffers-rs" }
regex = "0.2"
rusqlite = "0.10.1"
rustc-serialize = "0.3"
serde = "0.9"
serde_derive = "0.9"
serde_json = "0.9"
smallvec = "0.3"
rusqlite = "0.12"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
smallvec = "0.4"
time = "0.1"
tokio-core = "0.1"
tokio-signal = "0.1"
url = "1.4"
uuid = { version = "0.4", features = ["serde", "v4"] }
uuid = { version = "0.5", features = ["serde", "v4"] }
[dev-dependencies]
reqwest = "0.3"
reqwest = "0.6"
tempdir = "0.3"
[dependencies.cursive]
version = "0.4"
version = "0.5"
#default-features = false
#features = ["termion"]
@ -71,4 +70,4 @@ debug = true
[replace]
"https://github.com/hyperium/hyper#hyper:0.11.0-a.0" = { git = "https://github.com/scottlamb/hyper", branch = "moonfire-on-0.11.x" }
"hyper:0.10.5" = { git = "https://github.com/scottlamb/hyper", branch = "moonfire-on-0.10.x" }
"hyper:0.10.12" = { git = "https://github.com/scottlamb/hyper", branch = "moonfire-on-0.10.x" }

View File

@ -54,7 +54,7 @@ Options:
[default: /var/lib/moonfire-nvr/sample]
"#;
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
flag_db_dir: String,
flag_sample_file_dir: String,

View File

@ -211,9 +211,8 @@ fn edit_camera_dialog(db: &Arc<db::Database>, dir: &Arc<dir::SampleFileDir>, siv
let dialog = if let Some(id) = *item {
let l = db.lock();
let camera = l.cameras_by_id().get(&id).expect("missing camera");
dialog.find_id::<views::TextView>("uuid")
.expect("missing TextView")
.set_content(camera.uuid.to_string());
dialog.find_id("uuid", |v: &mut views::TextView| v.set_content(camera.uuid.to_string()))
.expect("missing TextView");
let bytes = camera.sample_file_bytes;
let name = camera.short_name.clone();
for &(view_id, content) in &[("short_name", &camera.short_name),
@ -222,13 +221,12 @@ fn edit_camera_dialog(db: &Arc<db::Database>, dir: &Arc<dir::SampleFileDir>, siv
("password", &camera.password),
("main_rtsp_path", &camera.main_rtsp_path),
("sub_rtsp_path", &camera.sub_rtsp_path)] {
dialog.find_id::<views::EditView>(view_id)
.expect("missing EditView")
.set_content(content.to_string());
dialog.find_id(view_id, |v: &mut views::EditView| v.set_content(content.to_string()))
.expect("missing EditView");
}
dialog.find_id::<views::TextArea>("description")
.expect("missing TextArea")
.set_content(camera.description.to_string());
dialog.find_id("description",
|v: &mut views::TextArea| v.set_content(camera.description.to_string()))
.expect("missing TextArea");
dialog.title("Edit camera")
.button("Edit", {
let db = db.clone();

View File

@ -120,7 +120,7 @@ fn decode_size(encoded: &str) -> Result<i64, ()> {
Ok(decoded)
}
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
flag_db_dir: String,
flag_sample_file_dir: String,

View File

@ -229,7 +229,7 @@ pub fn add_dialog(db: &Arc<db::Database>, dir: &Arc<dir::SampleFileDir>, siv: &m
move |siv, _| press_change(&model, siv)
})
.fixed_width(25))
.child(views::TextView::new("").with_id(&format!("{}_ok", id)).fixed_width(1)));
.child(views::TextView::new("").with_id(format!("{}_ok", id)).fixed_width(1)));
}
let over = model.borrow().total_retain > model.borrow().fs_capacity;
list.add_child(

View File

@ -46,7 +46,7 @@ Options:
[default: /var/lib/moonfire-nvr/db]
"#;
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
flag_db_dir: String,
}

View File

@ -42,7 +42,7 @@ mod run;
mod ts;
mod upgrade;
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
pub enum Command {
Check,
Config,
@ -95,8 +95,8 @@ fn open_conn(db_dir: &str, mode: OpenMode) -> Result<(dir::Fd, rusqlite::Connect
Ok((dir, conn))
}
fn parse_args<T>(usage: &str) -> Result<T, Error> where T: ::rustc_serialize::Decodable {
fn parse_args<'a, T>(usage: &str) -> Result<T, Error> where T: ::serde::Deserialize<'a> {
Ok(docopt::Docopt::new(usage)
.and_then(|d| d.decode())
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit()))
}

View File

@ -58,7 +58,7 @@ Options:
--read-only Forces read-only mode / disables recording.
"#;
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
flag_db_dir: String,
flag_sample_file_dir: String,

View File

@ -36,7 +36,7 @@ Usage: moonfire-nvr ts <ts>...
moonfire-nvr ts --help
"#;
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
arg_ts: Vec<String>,
}

View File

@ -68,7 +68,7 @@ const UPGRADERS: [fn(&rusqlite::Transaction) -> Result<(), Error>; 1] = [
v0_to_v1::run,
];
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
flag_db_dir: String,
flag_sample_file_dir: String,

View File

@ -1135,7 +1135,7 @@ impl LockedDatabase {
/// Inserts the specified video sample entry if absent.
/// On success, returns the id of a new or existing row.
pub fn insert_video_sample_entry(&mut self, w: u16, h: u16, data: &[u8]) -> Result<i32, Error> {
let sha1 = hash::hash(hash::MessageDigest::sha1(), data)?;
let sha1 = hash::hash2(hash::MessageDigest::sha1(), data)?;
let mut sha1_bytes = [0u8; 20];
sha1_bytes.copy_from_slice(&sha1);
@ -1155,7 +1155,7 @@ impl LockedDatabase {
let mut stmt = self.conn.prepare_cached(INSERT_VIDEO_SAMPLE_ENTRY_SQL)?;
stmt.execute_named(&[
(":sha1", &sha1),
(":sha1", &&sha1_bytes[..]),
(":width", &(w as i64)),
(":height", &(h as i64)),
(":data", &data),

View File

@ -657,7 +657,7 @@ impl<'a> InnerWriter<'a> {
self.index.add_sample(duration, unflushed.len, unflushed.is_key);
self.extend_local_start(unflushed.local_time);
let mut sha1_bytes = [0u8; 20];
sha1_bytes.copy_from_slice(&self.hasher.finish()?[..]);
sha1_bytes.copy_from_slice(&self.hasher.finish2()?[..]);
let start = self.prev_end.unwrap_or(self.local_start);
let end = start + recording::Duration(self.index.total_duration_90k as i64);
let flags = if self.index.has_trailing_zero() { db::RecordingFlags::TrailingZero as i32 }

View File

@ -46,12 +46,11 @@ extern crate lru_cache;
extern crate reffers;
extern crate rusqlite;
extern crate memmap;
#[macro_use] extern crate mime;
extern crate mime;
extern crate mylog;
extern crate openssl;
extern crate parking_lot;
extern crate regex;
extern crate rustc_serialize;
extern crate serde;
#[macro_use] extern crate serde_derive;
extern crate serde_json;
@ -100,7 +99,7 @@ Commands:
";
/// Commandline arguments corresponding to `USAGE`; automatically filled by the `docopt` crate.
#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
arg_command: Option<cmds::Command>,
}
@ -129,7 +128,7 @@ fn main() {
let args: Args = docopt::Docopt::new(USAGE)
.and_then(|d| d.options_first(true)
.version(Some(version()))
.decode())
.deserialize())
.unwrap_or_else(|e| e.exit());
let mut h = mylog::Builder::new()

View File

@ -101,7 +101,6 @@ use std::ops::Range;
use std::mem;
use std::sync::Arc;
use strutil;
use time::Timespec;
/// This value should be incremented any time a change is made to this file that causes different
/// bytes to be output for a particular set of `Mp4Builder` options. Incrementing this value will
@ -720,6 +719,8 @@ impl FileBuilder {
debug!("Estimated {} buf bytes; actually were {}", EST_BUF_LEN, self.body.buf.len());
}
debug!("slices: {:?}", self.body.slices);
let mtime = ::std::time::UNIX_EPOCH +
::std::time::Duration::from_secs(max_end.unix_seconds() as u64);
Ok(File(Arc::new(FileInner{
db: db,
dir: dir,
@ -728,8 +729,8 @@ impl FileBuilder {
buf: self.body.buf,
video_sample_entries: self.video_sample_entries,
initial_sample_byte_pos: initial_sample_byte_pos,
last_modified: header::HttpDate(time::at(Timespec::new(max_end.unix_seconds(), 0))),
etag: header::EntityTag::strong(strutil::hex(&etag.finish()?)),
last_modified: mtime.into(),
etag: header::EntityTag::strong(strutil::hex(&etag.finish2()?)),
})))
}
@ -1270,7 +1271,7 @@ mod tests {
}
/// Returns the SHA-1 digest of the given `Entity`.
fn digest(e: &http_entity::Entity<Body>) -> Vec<u8> {
fn digest(e: &http_entity::Entity<Body>) -> hash::DigestBytes {
e.get_range(0 .. e.len())
.fold(hash::Hasher::new(hash::MessageDigest::sha1()).unwrap(), |mut sha1, chunk| {
sha1.update(&chunk).unwrap();
@ -1278,7 +1279,7 @@ mod tests {
})
.wait()
.unwrap()
.finish()
.finish2()
.unwrap()
}

View File

@ -63,9 +63,6 @@ const BINARY_PREFIXES: &'static [&'static str] = &[" ", " Ki", " Mi", " Gi", " T
const DECIMAL_PREFIXES: &'static [&'static str] =&[" ", " k", " M", " G", " T", " P", " E"];
lazy_static! {
static ref JSON: mime::Mime = mime!(Application/Json);
static ref HTML: mime::Mime = mime!(Text/Html);
/// Regex used to parse the `s` query parameter to `view.mp4`.
/// As described in `design/api.md`, this is of the form
/// `START_ID[-END_ID][.[REL_START_TIME]-[REL_END_TIME]]`.
@ -112,8 +109,8 @@ fn decode_path(path: &str) -> Path {
fn is_json(req: &Request) -> bool {
if let Some(accept) = req.headers().get::<header::Accept>() {
return accept.len() == 1 && accept[0].item == *JSON &&
accept[0].quality == header::Quality(1000);
return accept.len() == 1 && accept[0].item == mime::APPLICATION_JSON &&
accept[0].quality == header::q(1000);
}
false
}
@ -229,7 +226,7 @@ impl Service {
fn not_found(&self) -> Result<Response<slices::Body>, Error> {
Ok(Response::new()
.with_status(status::StatusCode::NotFound)
.with_header(header::ContentType(mime!(Text/Plain)))
.with_header(header::ContentType(mime::TEXT_PLAIN))
.with_body(stream::once(Ok(ARefs::new(&b"not found"[..]))).boxed()))
}
@ -244,7 +241,8 @@ impl Service {
}
};
Ok(Response::new()
.with_header(header::ContentType(if json { JSON.clone() } else { HTML.clone() }))
.with_header(header::ContentType(if json { mime::APPLICATION_JSON }
else { mime::TEXT_HTML }))
.with_header(header::ContentLength(buf.len() as u64))
.with_body(stream::once(Ok(ARefs::new(buf))).boxed()))
}
@ -297,7 +295,8 @@ impl Service {
}
};
Ok(Response::new()
.with_header(header::ContentType(if json { JSON.clone() } else { HTML.clone() }))
.with_header(header::ContentType(if json { mime::APPLICATION_JSON }
else { mime::TEXT_HTML }))
.with_header(header::ContentLength(buf.len() as u64))
.with_body(stream::once(Ok(ARefs::new(buf))).boxed()))
}
@ -425,7 +424,7 @@ impl Service {
}
let buf = serde_json::to_vec(&out)?;
Ok(Response::new()
.with_header(header::ContentType(JSON.clone()))
.with_header(header::ContentType(mime::APPLICATION_JSON))
.with_header(header::ContentLength(buf.len() as u64))
.with_body(stream::once(Ok(ARefs::new(buf))).boxed()))
}