mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-01-12 15:33:22 -05:00
cargo fix --all
* it added "dyn" to trait objects * it changed "..." in patterns to "..=" cargo --version says: "cargo 1.37.0-nightly (545f35425 2019-05-23)"
This commit is contained in:
parent
7dd98bb76a
commit
7fe9d34655
@ -56,7 +56,7 @@ pub trait Clocks : Send + Sync + 'static {
|
|||||||
timeout: StdDuration) -> Result<T, mpsc::RecvTimeoutError>;
|
timeout: StdDuration) -> Result<T, mpsc::RecvTimeoutError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retry_forever<C, T, E>(clocks: &C, f: &mut FnMut() -> Result<T, E>) -> T
|
pub fn retry_forever<C, T, E>(clocks: &C, f: &mut dyn FnMut() -> Result<T, E>) -> T
|
||||||
where C: Clocks, E: Into<Error> {
|
where C: Clocks, E: Into<Error> {
|
||||||
loop {
|
loop {
|
||||||
let e = match f() {
|
let e = match f() {
|
||||||
|
@ -47,7 +47,7 @@ impl Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Fail for Error {
|
impl Fail for Error {
|
||||||
fn cause(&self) -> Option<&Fail> {
|
fn cause(&self) -> Option<&dyn Fail> {
|
||||||
self.inner.cause()
|
self.inner.cause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ pub fn hex(raw: &[u8]) -> String {
|
|||||||
/// Returns [0, 16) or error.
|
/// Returns [0, 16) or error.
|
||||||
fn dehex_byte(hex_byte: u8) -> Result<u8, ()> {
|
fn dehex_byte(hex_byte: u8) -> Result<u8, ()> {
|
||||||
match hex_byte {
|
match hex_byte {
|
||||||
b'0' ... b'9' => Ok(hex_byte - b'0'),
|
b'0' ..= b'9' => Ok(hex_byte - b'0'),
|
||||||
b'a' ... b'f' => Ok(hex_byte - b'a' + 10),
|
b'a' ..= b'f' => Ok(hex_byte - b'a' + 10),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ impl State {
|
|||||||
from
|
from
|
||||||
user
|
user
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id = row.get(0)?;
|
let id = row.get(0)?;
|
||||||
let name: String = row.get(1)?;
|
let name: String = row.get(1)?;
|
||||||
@ -596,7 +596,7 @@ impl State {
|
|||||||
let addr = req.addr_buf();
|
let addr = req.addr_buf();
|
||||||
let addr: Option<&[u8]> = addr.as_ref().map(|a| a.as_ref());
|
let addr: Option<&[u8]> = addr.as_ref().map(|a| a.as_ref());
|
||||||
stmt.execute(&[
|
stmt.execute(&[
|
||||||
&req.when_sec as &ToSql,
|
&req.when_sec as &dyn ToSql,
|
||||||
&req.user_agent,
|
&req.user_agent,
|
||||||
&addr,
|
&addr,
|
||||||
&(reason as i32),
|
&(reason as i32),
|
||||||
|
@ -58,7 +58,7 @@ pub fn run(conn: &rusqlite::Connection, opts: &Options) -> Result<(), Error> {
|
|||||||
"#)?;
|
"#)?;
|
||||||
let mut garbage_stmt = conn.prepare_cached(
|
let mut garbage_stmt = conn.prepare_cached(
|
||||||
"select composite_id from garbage where sample_file_dir_id = ?")?;
|
"select composite_id from garbage where sample_file_dir_id = ?")?;
|
||||||
let mut rows = dir_stmt.query(&[] as &[&ToSql])?;
|
let mut rows = dir_stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let mut meta = schema::DirMeta::default();
|
let mut meta = schema::DirMeta::default();
|
||||||
let dir_id: i32 = row.get(0)?;
|
let dir_id: i32 = row.get(0)?;
|
||||||
@ -92,7 +92,7 @@ pub fn run(conn: &rusqlite::Connection, opts: &Options) -> Result<(), Error> {
|
|||||||
let mut stmt = conn.prepare(r#"
|
let mut stmt = conn.prepare(r#"
|
||||||
select id, sample_file_dir_id from stream where sample_file_dir_id is not null
|
select id, sample_file_dir_id from stream where sample_file_dir_id is not null
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let stream_id = row.get(0)?;
|
let stream_id = row.get(0)?;
|
||||||
let dir_id = row.get(1)?;
|
let dir_id = row.get(1)?;
|
||||||
|
44
db/db.rs
44
db/db.rs
@ -446,7 +446,7 @@ pub struct Stream {
|
|||||||
/// The number of recordings in `uncommitted` which are synced and ready to commit.
|
/// The number of recordings in `uncommitted` which are synced and ready to commit.
|
||||||
synced_recordings: usize,
|
synced_recordings: usize,
|
||||||
|
|
||||||
on_live_segment: Vec<Box<FnMut(LiveSegment) -> bool + Send>>,
|
on_live_segment: Vec<Box<dyn FnMut(LiveSegment) -> bool + Send>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bounds of a single keyframe and the frames dependent on it.
|
/// Bounds of a single keyframe and the frames dependent on it.
|
||||||
@ -620,7 +620,7 @@ pub struct LockedDatabase {
|
|||||||
cameras_by_uuid: BTreeMap<Uuid, i32>, // values are ids.
|
cameras_by_uuid: BTreeMap<Uuid, i32>, // values are ids.
|
||||||
video_sample_entries_by_id: BTreeMap<i32, Arc<VideoSampleEntry>>,
|
video_sample_entries_by_id: BTreeMap<i32, Arc<VideoSampleEntry>>,
|
||||||
video_index_cache: RefCell<LruCache<i64, Box<[u8]>, fnv::FnvBuildHasher>>,
|
video_index_cache: RefCell<LruCache<i64, Box<[u8]>, fnv::FnvBuildHasher>>,
|
||||||
on_flush: Vec<Box<Fn() + Send>>,
|
on_flush: Vec<Box<dyn Fn() + Send>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a row of the `open` database table.
|
/// Represents a row of the `open` database table.
|
||||||
@ -867,7 +867,7 @@ impl LockedDatabase {
|
|||||||
/// Registers a callback to run on every live segment immediately after it's recorded.
|
/// Registers a callback to run on every live segment immediately after it's recorded.
|
||||||
/// The callback is run with the database lock held, so it must not call back into the database
|
/// The callback is run with the database lock held, so it must not call back into the database
|
||||||
/// or block. The callback should return false to unregister.
|
/// or block. The callback should return false to unregister.
|
||||||
pub fn watch_live(&mut self, stream_id: i32, cb: Box<FnMut(LiveSegment) -> bool + Send>)
|
pub fn watch_live(&mut self, stream_id: i32, cb: Box<dyn FnMut(LiveSegment) -> bool + Send>)
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
let s = match self.streams_by_id.get_mut(&stream_id) {
|
let s = match self.streams_by_id.get_mut(&stream_id) {
|
||||||
None => bail!("no such stream {}", stream_id),
|
None => bail!("no such stream {}", stream_id),
|
||||||
@ -958,7 +958,7 @@ impl LockedDatabase {
|
|||||||
let mut stmt = tx.prepare_cached(
|
let mut stmt = tx.prepare_cached(
|
||||||
r"update open set duration_90k = ?, end_time_90k = ? where id = ?")?;
|
r"update open set duration_90k = ?, end_time_90k = ? where id = ?")?;
|
||||||
let rows = stmt.execute(&[
|
let rows = stmt.execute(&[
|
||||||
&(recording::Time::new(clocks.monotonic()) - self.open_monotonic).0 as &ToSql,
|
&(recording::Time::new(clocks.monotonic()) - self.open_monotonic).0 as &dyn ToSql,
|
||||||
&recording::Time::new(clocks.realtime()).0,
|
&recording::Time::new(clocks.realtime()).0,
|
||||||
&o.id,
|
&o.id,
|
||||||
])?;
|
])?;
|
||||||
@ -1024,7 +1024,7 @@ impl LockedDatabase {
|
|||||||
|
|
||||||
/// Sets a watcher which will receive an (empty) event on successful flush.
|
/// Sets a watcher which will receive an (empty) event on successful flush.
|
||||||
/// The lock will be held while this is run, so it should not do any I/O.
|
/// The lock will be held while this is run, so it should not do any I/O.
|
||||||
pub(crate) fn on_flush(&mut self, run: Box<Fn() + Send>) {
|
pub(crate) fn on_flush(&mut self, run: Box<dyn Fn() + Send>) {
|
||||||
self.on_flush.push(run);
|
self.on_flush.push(run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1084,7 +1084,7 @@ impl LockedDatabase {
|
|||||||
update sample_file_dir set last_complete_open_id = ? where id = ?
|
update sample_file_dir set last_complete_open_id = ? where id = ?
|
||||||
"#)?;
|
"#)?;
|
||||||
for &id in in_progress.keys() {
|
for &id in in_progress.keys() {
|
||||||
if stmt.execute(&[&o.id as &ToSql, &id])? != 1 {
|
if stmt.execute(&[&o.id as &dyn ToSql, &id])? != 1 {
|
||||||
bail!("unable to update dir {}", id);
|
bail!("unable to update dir {}", id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1124,7 +1124,7 @@ impl LockedDatabase {
|
|||||||
/// Uncommitted recordings are returned id order after the others.
|
/// Uncommitted recordings are returned id order after the others.
|
||||||
pub fn list_recordings_by_time(
|
pub fn list_recordings_by_time(
|
||||||
&self, stream_id: i32, desired_time: Range<recording::Time>,
|
&self, stream_id: i32, desired_time: Range<recording::Time>,
|
||||||
f: &mut FnMut(ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
f: &mut dyn FnMut(ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
||||||
let s = match self.streams_by_id.get(&stream_id) {
|
let s = match self.streams_by_id.get(&stream_id) {
|
||||||
None => bail!("no such stream {}", stream_id),
|
None => bail!("no such stream {}", stream_id),
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
@ -1152,7 +1152,7 @@ impl LockedDatabase {
|
|||||||
/// Lists the specified recordings in ascending order by id.
|
/// Lists the specified recordings in ascending order by id.
|
||||||
pub fn list_recordings_by_id(
|
pub fn list_recordings_by_id(
|
||||||
&self, stream_id: i32, desired_ids: Range<i32>,
|
&self, stream_id: i32, desired_ids: Range<i32>,
|
||||||
f: &mut FnMut(ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
f: &mut dyn FnMut(ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
||||||
let s = match self.streams_by_id.get(&stream_id) {
|
let s = match self.streams_by_id.get(&stream_id) {
|
||||||
None => bail!("no such stream {}", stream_id),
|
None => bail!("no such stream {}", stream_id),
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
@ -1186,7 +1186,7 @@ impl LockedDatabase {
|
|||||||
pub fn list_aggregated_recordings(
|
pub fn list_aggregated_recordings(
|
||||||
&self, stream_id: i32, desired_time: Range<recording::Time>,
|
&self, stream_id: i32, desired_time: Range<recording::Time>,
|
||||||
forced_split: recording::Duration,
|
forced_split: recording::Duration,
|
||||||
f: &mut FnMut(&ListAggregatedRecordingsRow) -> Result<(), Error>)
|
f: &mut dyn FnMut(&ListAggregatedRecordingsRow) -> Result<(), Error>)
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
// Iterate, maintaining a map from a recording_id to the aggregated row for the latest
|
// Iterate, maintaining a map from a recording_id to the aggregated row for the latest
|
||||||
// batch of recordings from the run starting at that id. Runs can be split into multiple
|
// batch of recordings from the run starting at that id. Runs can be split into multiple
|
||||||
@ -1255,7 +1255,7 @@ impl LockedDatabase {
|
|||||||
/// Note the lock is held for the duration of `f`.
|
/// Note the lock is held for the duration of `f`.
|
||||||
/// This uses a LRU cache to reduce the number of retrievals from the database.
|
/// This uses a LRU cache to reduce the number of retrievals from the database.
|
||||||
pub fn with_recording_playback<R>(&self, id: CompositeId,
|
pub fn with_recording_playback<R>(&self, id: CompositeId,
|
||||||
f: &mut FnMut(&RecordingPlayback) -> Result<R, Error>)
|
f: &mut dyn FnMut(&RecordingPlayback) -> Result<R, Error>)
|
||||||
-> Result<R, Error> {
|
-> Result<R, Error> {
|
||||||
// Check for uncommitted path.
|
// Check for uncommitted path.
|
||||||
let s = self.streams_by_id
|
let s = self.streams_by_id
|
||||||
@ -1292,7 +1292,7 @@ impl LockedDatabase {
|
|||||||
/// Deletes the oldest recordings that aren't already queued for deletion.
|
/// Deletes the oldest recordings that aren't already queued for deletion.
|
||||||
/// `f` should return true for each row that should be deleted.
|
/// `f` should return true for each row that should be deleted.
|
||||||
pub(crate) fn delete_oldest_recordings(
|
pub(crate) fn delete_oldest_recordings(
|
||||||
&mut self, stream_id: i32, f: &mut FnMut(&ListOldestRecordingsRow) -> bool)
|
&mut self, stream_id: i32, f: &mut dyn FnMut(&ListOldestRecordingsRow) -> bool)
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
let s = match self.streams_by_id.get_mut(&stream_id) {
|
let s = match self.streams_by_id.get_mut(&stream_id) {
|
||||||
None => bail!("no stream {}", stream_id),
|
None => bail!("no stream {}", stream_id),
|
||||||
@ -1326,7 +1326,7 @@ impl LockedDatabase {
|
|||||||
from
|
from
|
||||||
video_sample_entry
|
video_sample_entry
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id = row.get(0)?;
|
let id = row.get(0)?;
|
||||||
let mut sha1 = [0u8; 20];
|
let mut sha1 = [0u8; 20];
|
||||||
@ -1365,7 +1365,7 @@ impl LockedDatabase {
|
|||||||
from
|
from
|
||||||
sample_file_dir d left join open o on (d.last_complete_open_id = o.id);
|
sample_file_dir d left join open o on (d.last_complete_open_id = o.id);
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id = row.get(0)?;
|
let id = row.get(0)?;
|
||||||
let dir_uuid: FromSqlUuid = row.get(2)?;
|
let dir_uuid: FromSqlUuid = row.get(2)?;
|
||||||
@ -1406,7 +1406,7 @@ impl LockedDatabase {
|
|||||||
from
|
from
|
||||||
camera;
|
camera;
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id = row.get(0)?;
|
let id = row.get(0)?;
|
||||||
let uuid: FromSqlUuid = row.get(1)?;
|
let uuid: FromSqlUuid = row.get(1)?;
|
||||||
@ -1444,7 +1444,7 @@ impl LockedDatabase {
|
|||||||
from
|
from
|
||||||
stream;
|
stream;
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id = row.get(0)?;
|
let id = row.get(0)?;
|
||||||
let type_: String = row.get(1)?;
|
let type_: String = row.get(1)?;
|
||||||
@ -1549,7 +1549,7 @@ impl LockedDatabase {
|
|||||||
self.conn.execute(r#"
|
self.conn.execute(r#"
|
||||||
insert into sample_file_dir (path, uuid, last_complete_open_id)
|
insert into sample_file_dir (path, uuid, last_complete_open_id)
|
||||||
values (?, ?, ?)
|
values (?, ?, ?)
|
||||||
"#, &[&path as &ToSql, &uuid_bytes, &o.id])?;
|
"#, &[&path as &dyn ToSql, &uuid_bytes, &o.id])?;
|
||||||
let id = self.conn.last_insert_rowid() as i32;
|
let id = self.conn.last_insert_rowid() as i32;
|
||||||
use ::std::collections::btree_map::Entry;
|
use ::std::collections::btree_map::Entry;
|
||||||
let e = self.sample_file_dirs_by_id.entry(id);
|
let e = self.sample_file_dirs_by_id.entry(id);
|
||||||
@ -1796,7 +1796,7 @@ impl LockedDatabase {
|
|||||||
self.signal.types_by_uuid()
|
self.signal.types_by_uuid()
|
||||||
}
|
}
|
||||||
pub fn list_changes_by_time(
|
pub fn list_changes_by_time(
|
||||||
&self, desired_time: Range<recording::Time>, f: &mut FnMut(&signal::ListStateChangesRow)) {
|
&self, desired_time: Range<recording::Time>, f: &mut dyn FnMut(&signal::ListStateChangesRow)) {
|
||||||
self.signal.list_changes_by_time(desired_time, f)
|
self.signal.list_changes_by_time(desired_time, f)
|
||||||
}
|
}
|
||||||
pub fn update_signals(
|
pub fn update_signals(
|
||||||
@ -1810,7 +1810,7 @@ impl LockedDatabase {
|
|||||||
/// Note this doesn't set journal options, so that it can be used on in-memory databases for
|
/// Note this doesn't set journal options, so that it can be used on in-memory databases for
|
||||||
/// test code.
|
/// test code.
|
||||||
pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
||||||
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
conn.execute("pragma foreign_keys = on", &[] as &[&dyn ToSql])?;
|
||||||
let tx = conn.transaction()?;
|
let tx = conn.transaction()?;
|
||||||
tx.execute_batch(include_str!("schema.sql"))?;
|
tx.execute_batch(include_str!("schema.sql"))?;
|
||||||
{
|
{
|
||||||
@ -1829,11 +1829,11 @@ pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
|||||||
pub fn get_schema_version(conn: &rusqlite::Connection) -> Result<Option<i32>, Error> {
|
pub fn get_schema_version(conn: &rusqlite::Connection) -> Result<Option<i32>, Error> {
|
||||||
let ver_tables: i32 = conn.query_row_and_then(
|
let ver_tables: i32 = conn.query_row_and_then(
|
||||||
"select count(*) from sqlite_master where name = 'version'",
|
"select count(*) from sqlite_master where name = 'version'",
|
||||||
&[] as &[&ToSql], |row| row.get(0))?;
|
&[] as &[&dyn ToSql], |row| row.get(0))?;
|
||||||
if ver_tables == 0 {
|
if ver_tables == 0 {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
Ok(Some(conn.query_row_and_then("select max(id) from version", &[] as &[&ToSql],
|
Ok(Some(conn.query_row_and_then("select max(id) from version", &[] as &[&dyn ToSql],
|
||||||
|row| row.get(0))?))
|
|row| row.get(0))?))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1871,7 +1871,7 @@ impl<C: Clocks + Clone> Database<C> {
|
|||||||
/// Creates the database from a caller-supplied SQLite connection.
|
/// Creates the database from a caller-supplied SQLite connection.
|
||||||
pub fn new(clocks: C, conn: rusqlite::Connection,
|
pub fn new(clocks: C, conn: rusqlite::Connection,
|
||||||
read_write: bool) -> Result<Database<C>, Error> {
|
read_write: bool) -> Result<Database<C>, Error> {
|
||||||
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
conn.execute("pragma foreign_keys = on", &[] as &[&dyn ToSql])?;
|
||||||
{
|
{
|
||||||
let ver = get_schema_version(&conn)?.ok_or_else(|| format_err!(
|
let ver = get_schema_version(&conn)?.ok_or_else(|| format_err!(
|
||||||
"no such table: version. \
|
"no such table: version. \
|
||||||
@ -1901,7 +1901,7 @@ impl<C: Clocks + Clone> Database<C> {
|
|||||||
let mut stmt = conn.prepare(" insert into open (uuid, start_time_90k) values (?, ?)")?;
|
let mut stmt = conn.prepare(" insert into open (uuid, start_time_90k) values (?, ?)")?;
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
let uuid_bytes = &uuid.as_bytes()[..];
|
let uuid_bytes = &uuid.as_bytes()[..];
|
||||||
stmt.execute(&[&uuid_bytes as &ToSql, &real.0])?;
|
stmt.execute(&[&uuid_bytes as &dyn ToSql, &real.0])?;
|
||||||
Some(Open {
|
Some(Open {
|
||||||
id: conn.last_insert_rowid() as u32,
|
id: conn.last_insert_rowid() as u32,
|
||||||
uuid,
|
uuid,
|
||||||
|
@ -302,8 +302,8 @@ pub(crate) fn parse_id(id: &[u8]) -> Result<CompositeId, ()> {
|
|||||||
let mut v: u64 = 0;
|
let mut v: u64 = 0;
|
||||||
for i in 0..16 {
|
for i in 0..16 {
|
||||||
v = (v << 4) | match id[i] {
|
v = (v << 4) | match id[i] {
|
||||||
b @ b'0'...b'9' => b - b'0',
|
b @ b'0'..=b'9' => b - b'0',
|
||||||
b @ b'a'...b'f' => b - b'a' + 10,
|
b @ b'a'..=b'f' => b - b'a' + 10,
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
} as u64;
|
} as u64;
|
||||||
}
|
}
|
||||||
|
12
db/raw.rs
12
db/raw.rs
@ -123,7 +123,7 @@ const LIST_OLDEST_RECORDINGS_SQL: &'static str = r#"
|
|||||||
/// function. Given that the function is called with the database lock held, it should be quick.
|
/// function. Given that the function is called with the database lock held, it should be quick.
|
||||||
pub(crate) fn list_recordings_by_time(
|
pub(crate) fn list_recordings_by_time(
|
||||||
conn: &rusqlite::Connection, stream_id: i32, desired_time: Range<recording::Time>,
|
conn: &rusqlite::Connection, stream_id: i32, desired_time: Range<recording::Time>,
|
||||||
f: &mut FnMut(db::ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
f: &mut dyn FnMut(db::ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
||||||
let mut stmt = conn.prepare_cached(LIST_RECORDINGS_BY_TIME_SQL)?;
|
let mut stmt = conn.prepare_cached(LIST_RECORDINGS_BY_TIME_SQL)?;
|
||||||
let rows = stmt.query_named(&[
|
let rows = stmt.query_named(&[
|
||||||
(":stream_id", &stream_id),
|
(":stream_id", &stream_id),
|
||||||
@ -135,7 +135,7 @@ pub(crate) fn list_recordings_by_time(
|
|||||||
/// Lists the specified recordings in ascending order by id.
|
/// Lists the specified recordings in ascending order by id.
|
||||||
pub(crate) fn list_recordings_by_id(
|
pub(crate) fn list_recordings_by_id(
|
||||||
conn: &rusqlite::Connection, stream_id: i32, desired_ids: Range<i32>,
|
conn: &rusqlite::Connection, stream_id: i32, desired_ids: Range<i32>,
|
||||||
f: &mut FnMut(db::ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
f: &mut dyn FnMut(db::ListRecordingsRow) -> Result<(), Error>) -> Result<(), Error> {
|
||||||
let mut stmt = conn.prepare_cached(LIST_RECORDINGS_BY_ID_SQL)?;
|
let mut stmt = conn.prepare_cached(LIST_RECORDINGS_BY_ID_SQL)?;
|
||||||
let rows = stmt.query_named(&[
|
let rows = stmt.query_named(&[
|
||||||
(":start", &CompositeId::new(stream_id, desired_ids.start).0),
|
(":start", &CompositeId::new(stream_id, desired_ids.start).0),
|
||||||
@ -145,7 +145,7 @@ pub(crate) fn list_recordings_by_id(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn list_recordings_inner(mut rows: rusqlite::Rows,
|
fn list_recordings_inner(mut rows: rusqlite::Rows,
|
||||||
f: &mut FnMut(db::ListRecordingsRow) -> Result<(), Error>)
|
f: &mut dyn FnMut(db::ListRecordingsRow) -> Result<(), Error>)
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
f(db::ListRecordingsRow {
|
f(db::ListRecordingsRow {
|
||||||
@ -165,7 +165,7 @@ fn list_recordings_inner(mut rows: rusqlite::Rows,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_db_uuid(conn: &rusqlite::Connection) -> Result<Uuid, Error> {
|
pub(crate) fn get_db_uuid(conn: &rusqlite::Connection) -> Result<Uuid, Error> {
|
||||||
Ok(conn.query_row("select uuid from meta", &[] as &[&ToSql], |row| -> rusqlite::Result<Uuid> {
|
Ok(conn.query_row("select uuid from meta", &[] as &[&dyn ToSql], |row| -> rusqlite::Result<Uuid> {
|
||||||
let uuid: FromSqlUuid = row.get(0)?;
|
let uuid: FromSqlUuid = row.get(0)?;
|
||||||
Ok(uuid.0)
|
Ok(uuid.0)
|
||||||
})?)
|
})?)
|
||||||
@ -266,7 +266,7 @@ pub(crate) fn delete_recordings(tx: &rusqlite::Transaction, sample_file_dir_id:
|
|||||||
(":start", &ids.start.0),
|
(":start", &ids.start.0),
|
||||||
(":end", &ids.end.0),
|
(":end", &ids.end.0),
|
||||||
])?;
|
])?;
|
||||||
let p: &[(&str, &rusqlite::types::ToSql)] = &[
|
let p: &[(&str, &dyn rusqlite::types::ToSql)] = &[
|
||||||
(":start", &ids.start.0),
|
(":start", &ids.start.0),
|
||||||
(":end", &ids.end.0),
|
(":end", &ids.end.0),
|
||||||
];
|
];
|
||||||
@ -360,7 +360,7 @@ pub(crate) fn list_garbage(conn: &rusqlite::Connection, dir_id: i32)
|
|||||||
/// Lists the oldest recordings for a stream, starting with the given id.
|
/// Lists the oldest recordings for a stream, starting with the given id.
|
||||||
/// `f` should return true as long as further rows are desired.
|
/// `f` should return true as long as further rows are desired.
|
||||||
pub(crate) fn list_oldest_recordings(conn: &rusqlite::Connection, start: CompositeId,
|
pub(crate) fn list_oldest_recordings(conn: &rusqlite::Connection, start: CompositeId,
|
||||||
f: &mut FnMut(db::ListOldestRecordingsRow) -> bool)
|
f: &mut dyn FnMut(db::ListOldestRecordingsRow) -> bool)
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
let mut stmt = conn.prepare_cached(LIST_OLDEST_RECORDINGS_SQL)?;
|
let mut stmt = conn.prepare_cached(LIST_OLDEST_RECORDINGS_SQL)?;
|
||||||
let mut rows = stmt.query_named(&[
|
let mut rows = stmt.query_named(&[
|
||||||
|
20
db/schema.rs
20
db/schema.rs
@ -252,13 +252,13 @@ impl ::protobuf::Message for DirMeta {
|
|||||||
&mut self.unknown_fields
|
&mut self.unknown_fields
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &::std::any::Any {
|
fn as_any(&self) -> &dyn (::std::any::Any) {
|
||||||
self as &::std::any::Any
|
self as &dyn (::std::any::Any)
|
||||||
}
|
}
|
||||||
fn as_any_mut(&mut self) -> &mut ::std::any::Any {
|
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
|
||||||
self as &mut ::std::any::Any
|
self as &mut dyn (::std::any::Any)
|
||||||
}
|
}
|
||||||
fn into_any(self: Box<Self>) -> ::std::boxed::Box<::std::any::Any> {
|
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,13 +462,13 @@ impl ::protobuf::Message for DirMeta_Open {
|
|||||||
&mut self.unknown_fields
|
&mut self.unknown_fields
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &::std::any::Any {
|
fn as_any(&self) -> &dyn (::std::any::Any) {
|
||||||
self as &::std::any::Any
|
self as &dyn (::std::any::Any)
|
||||||
}
|
}
|
||||||
fn as_any_mut(&mut self) -> &mut ::std::any::Any {
|
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
|
||||||
self as &mut ::std::any::Any
|
self as &mut dyn (::std::any::Any)
|
||||||
}
|
}
|
||||||
fn into_any(self: Box<Self>) -> ::std::boxed::Box<::std::any::Any> {
|
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_changes_by_time(
|
pub fn list_changes_by_time(
|
||||||
&self, desired_time: Range<recording::Time>, f: &mut FnMut(&ListStateChangesRow)) {
|
&self, desired_time: Range<recording::Time>, f: &mut dyn FnMut(&ListStateChangesRow)) {
|
||||||
|
|
||||||
// First find the state immediately before. If it exists, include it.
|
// First find the state immediately before. If it exists, include it.
|
||||||
if let Some((&when, p)) = self.points_by_time.range(..desired_time.start).next_back() {
|
if let Some((&when, p)) = self.points_by_time.range(..desired_time.start).next_back() {
|
||||||
|
@ -54,7 +54,7 @@ pub struct Args<'a> {
|
|||||||
|
|
||||||
fn set_journal_mode(conn: &rusqlite::Connection, requested: &str) -> Result<(), Error> {
|
fn set_journal_mode(conn: &rusqlite::Connection, requested: &str) -> Result<(), Error> {
|
||||||
assert!(!requested.contains(';')); // quick check for accidental sql injection.
|
assert!(!requested.contains(';')); // quick check for accidental sql injection.
|
||||||
let actual = conn.query_row(&format!("pragma journal_mode = {}", requested), &[] as &[&ToSql],
|
let actual = conn.query_row(&format!("pragma journal_mode = {}", requested), &[] as &[&dyn ToSql],
|
||||||
|row| row.get::<_, String>(0))?;
|
|row| row.get::<_, String>(0))?;
|
||||||
info!("...database now in journal_mode {} (requested {}).", actual, requested);
|
info!("...database now in journal_mode {} (requested {}).", actual, requested);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -71,7 +71,7 @@ pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
|||||||
{
|
{
|
||||||
assert_eq!(upgraders.len(), db::EXPECTED_VERSION as usize);
|
assert_eq!(upgraders.len(), db::EXPECTED_VERSION as usize);
|
||||||
let old_ver =
|
let old_ver =
|
||||||
conn.query_row("select max(id) from version", &[] as &[&ToSql],
|
conn.query_row("select max(id) from version", &[] as &[&dyn ToSql],
|
||||||
|row| row.get(0))?;
|
|row| row.get(0))?;
|
||||||
if old_ver > db::EXPECTED_VERSION {
|
if old_ver > db::EXPECTED_VERSION {
|
||||||
bail!("Database is at version {}, later than expected {}",
|
bail!("Database is at version {}, later than expected {}",
|
||||||
@ -88,7 +88,7 @@ pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
|||||||
tx.execute(r#"
|
tx.execute(r#"
|
||||||
insert into version (id, unix_time, notes)
|
insert into version (id, unix_time, notes)
|
||||||
values (?, cast(strftime('%s', 'now') as int32), ?)
|
values (?, cast(strftime('%s', 'now') as int32), ?)
|
||||||
"#, &[&(ver + 1) as &ToSql, &UPGRADE_NOTES])?;
|
"#, &[&(ver + 1) as &dyn ToSql, &UPGRADE_NOTES])?;
|
||||||
tx.commit()?;
|
tx.commit()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
|||||||
// compiles the SQLite3 amalgamation with -DSQLITE_DEFAULT_FOREIGN_KEYS=1). Ensure it's
|
// compiles the SQLite3 amalgamation with -DSQLITE_DEFAULT_FOREIGN_KEYS=1). Ensure it's
|
||||||
// always on. Note that our foreign keys are immediate rather than deferred, so we have to
|
// always on. Note that our foreign keys are immediate rather than deferred, so we have to
|
||||||
// be careful about the order of operations during the upgrade.
|
// be careful about the order of operations during the upgrade.
|
||||||
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
conn.execute("pragma foreign_keys = on", &[] as &[&dyn ToSql])?;
|
||||||
|
|
||||||
// WAL is the preferred journal mode for normal operation; it reduces the number of syncs
|
// WAL is the preferred journal mode for normal operation; it reduces the number of syncs
|
||||||
// without compromising safety.
|
// without compromising safety.
|
||||||
|
@ -142,7 +142,7 @@ fn fill_recording(tx: &rusqlite::Transaction) -> Result<HashMap<i32, CameraState
|
|||||||
insert into recording_playback values (:composite_id, :sample_file_uuid, :sample_file_sha1,
|
insert into recording_playback values (:composite_id, :sample_file_uuid, :sample_file_sha1,
|
||||||
:video_index)
|
:video_index)
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = select.query(&[] as &[&ToSql])?;
|
let mut rows = select.query(&[] as &[&dyn ToSql])?;
|
||||||
let mut camera_state: HashMap<i32, CameraState> = HashMap::new();
|
let mut camera_state: HashMap<i32, CameraState> = HashMap::new();
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let camera_id: i32 = row.get(0)?;
|
let camera_id: i32 = row.get(0)?;
|
||||||
@ -216,7 +216,7 @@ fn fill_camera(tx: &rusqlite::Transaction, camera_state: HashMap<i32, CameraStat
|
|||||||
insert into camera values (:id, :uuid, :short_name, :description, :host, :username, :password,
|
insert into camera values (:id, :uuid, :short_name, :description, :host, :username, :password,
|
||||||
:main_rtsp_path, :sub_rtsp_path, :retain_bytes, :next_recording_id)
|
:main_rtsp_path, :sub_rtsp_path, :retain_bytes, :next_recording_id)
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = select.query(&[] as &[&ToSql])?;
|
let mut rows = select.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id: i32 = row.get(0)?;
|
let id: i32 = row.get(0)?;
|
||||||
let uuid: Vec<u8> = row.get(1)?;
|
let uuid: Vec<u8> = row.get(1)?;
|
||||||
|
@ -122,7 +122,7 @@ pub fn run(args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
|
|||||||
tx.execute(r#"
|
tx.execute(r#"
|
||||||
insert into sample_file_dir (path, uuid, last_complete_open_id)
|
insert into sample_file_dir (path, uuid, last_complete_open_id)
|
||||||
values (?, ?, ?)
|
values (?, ?, ?)
|
||||||
"#, &[&sample_file_path as &ToSql, &dir_uuid_bytes, &open_id])?;
|
"#, &[&sample_file_path as &dyn ToSql, &dir_uuid_bytes, &open_id])?;
|
||||||
|
|
||||||
tx.execute_batch(r#"
|
tx.execute_batch(r#"
|
||||||
drop table reserved_sample_files;
|
drop table reserved_sample_files;
|
||||||
@ -298,7 +298,7 @@ fn verify_dir_contents(sample_file_path: &str, tx: &rusqlite::Transaction) -> Re
|
|||||||
from
|
from
|
||||||
(select count(*) as c from recording) a,
|
(select count(*) as c from recording) a,
|
||||||
(select count(*) as c from reserved_sample_files) b;
|
(select count(*) as c from reserved_sample_files) b;
|
||||||
"#, &[] as &[&ToSql], |r| r.get(0))?;
|
"#, &[] as &[&dyn ToSql], |r| r.get(0))?;
|
||||||
let mut files = ::fnv::FnvHashSet::with_capacity_and_hasher(n as usize, Default::default());
|
let mut files = ::fnv::FnvHashSet::with_capacity_and_hasher(n as usize, Default::default());
|
||||||
for e in fs::read_dir(sample_file_path)? {
|
for e in fs::read_dir(sample_file_path)? {
|
||||||
let e = e?;
|
let e = e?;
|
||||||
@ -329,7 +329,7 @@ fn verify_dir_contents(sample_file_path: &str, tx: &rusqlite::Transaction) -> Re
|
|||||||
// Iterate through the database and check that everything has a matching file.
|
// Iterate through the database and check that everything has a matching file.
|
||||||
{
|
{
|
||||||
let mut stmt = tx.prepare(r"select sample_file_uuid from recording_playback")?;
|
let mut stmt = tx.prepare(r"select sample_file_uuid from recording_playback")?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let uuid: crate::db::FromSqlUuid = row.get(0)?;
|
let uuid: crate::db::FromSqlUuid = row.get(0)?;
|
||||||
if !files.remove(&uuid.0) {
|
if !files.remove(&uuid.0) {
|
||||||
@ -339,7 +339,7 @@ fn verify_dir_contents(sample_file_path: &str, tx: &rusqlite::Transaction) -> Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut stmt = tx.prepare(r"select uuid from reserved_sample_files")?;
|
let mut stmt = tx.prepare(r"select uuid from reserved_sample_files")?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let uuid: crate::db::FromSqlUuid = row.get(0)?;
|
let uuid: crate::db::FromSqlUuid = row.get(0)?;
|
||||||
files.remove(&uuid.0);
|
files.remove(&uuid.0);
|
||||||
@ -366,7 +366,7 @@ fn fix_video_sample_entry(tx: &rusqlite::Transaction) -> Result<(), Error> {
|
|||||||
let mut insert = tx.prepare(r#"
|
let mut insert = tx.prepare(r#"
|
||||||
insert into video_sample_entry values (:id, :sha1, :width, :height, :rfc6381_codec, :data)
|
insert into video_sample_entry values (:id, :sha1, :width, :height, :rfc6381_codec, :data)
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = select.query(&[] as &[&ToSql])?;
|
let mut rows = select.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let data: Vec<u8> = row.get(4)?;
|
let data: Vec<u8> = row.get(4)?;
|
||||||
insert.execute_named(&[
|
insert.execute_named(&[
|
||||||
|
@ -57,7 +57,7 @@ fn open_sample_file_dir(tx: &rusqlite::Transaction) -> Result<Arc<dir::SampleFil
|
|||||||
sample_file_dir s
|
sample_file_dir s
|
||||||
join open o on (s.last_complete_open_id = o.id)
|
join open o on (s.last_complete_open_id = o.id)
|
||||||
cross join meta m
|
cross join meta m
|
||||||
"#, &[] as &[&ToSql], |row| {
|
"#, &[] as &[&dyn ToSql], |row| {
|
||||||
Ok((row.get(0)?,
|
Ok((row.get(0)?,
|
||||||
row.get(1)?,
|
row.get(1)?,
|
||||||
row.get(2)?,
|
row.get(2)?,
|
||||||
@ -84,7 +84,7 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
|
|||||||
from
|
from
|
||||||
recording_playback
|
recording_playback
|
||||||
"#)?;
|
"#)?;
|
||||||
let mut rows = stmt.query(&[] as &[&ToSql])?;
|
let mut rows = stmt.query(&[] as &[&dyn ToSql])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let id = db::CompositeId(row.get(0)?);
|
let id = db::CompositeId(row.get(0)?);
|
||||||
let sample_file_uuid: FromSqlUuid = row.get(1)?;
|
let sample_file_uuid: FromSqlUuid = row.get(1)?;
|
||||||
|
10
db/writer.rs
10
db/writer.rs
@ -867,9 +867,9 @@ mod tests {
|
|||||||
struct MockDir(Arc<Mutex<VecDeque<MockDirAction>>>);
|
struct MockDir(Arc<Mutex<VecDeque<MockDirAction>>>);
|
||||||
|
|
||||||
enum MockDirAction {
|
enum MockDirAction {
|
||||||
Create(CompositeId, Box<Fn(CompositeId) -> Result<MockFile, io::Error> + Send>),
|
Create(CompositeId, Box<dyn Fn(CompositeId) -> Result<MockFile, io::Error> + Send>),
|
||||||
Sync(Box<Fn() -> Result<(), io::Error> + Send>),
|
Sync(Box<dyn Fn() -> Result<(), io::Error> + Send>),
|
||||||
Unlink(CompositeId, Box<Fn(CompositeId) -> Result<(), io::Error> + Send>),
|
Unlink(CompositeId, Box<dyn Fn(CompositeId) -> Result<(), io::Error> + Send>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MockDir {
|
impl MockDir {
|
||||||
@ -919,8 +919,8 @@ mod tests {
|
|||||||
struct MockFile(Arc<Mutex<VecDeque<MockFileAction>>>);
|
struct MockFile(Arc<Mutex<VecDeque<MockFileAction>>>);
|
||||||
|
|
||||||
enum MockFileAction {
|
enum MockFileAction {
|
||||||
SyncAll(Box<Fn() -> Result<(), io::Error> + Send>),
|
SyncAll(Box<dyn Fn() -> Result<(), io::Error> + Send>),
|
||||||
Write(Box<Fn(&[u8]) -> Result<usize, io::Error> + Send>),
|
Write(Box<dyn Fn(&[u8]) -> Result<usize, io::Error> + Send>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MockFile {
|
impl MockFile {
|
||||||
|
@ -323,7 +323,7 @@ impl std::error::Error for Error {
|
|||||||
"ffmpeg error"
|
"ffmpeg error"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cause(&self) -> Option<&std::error::Error> { None }
|
fn cause(&self) -> Option<&dyn std::error::Error> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
|
@ -39,8 +39,8 @@ use std::error::Error as StdError;
|
|||||||
pub struct Chunk(ARefs<'static, [u8]>);
|
pub struct Chunk(ARefs<'static, [u8]>);
|
||||||
|
|
||||||
//pub type CompatError = ::failure::Compat<Error>;
|
//pub type CompatError = ::failure::Compat<Error>;
|
||||||
pub type BoxedError = Box<StdError + Send + Sync>;
|
pub type BoxedError = Box<dyn StdError + Send + Sync>;
|
||||||
pub type BodyStream = Box<Stream<Item = Chunk, Error = BoxedError> + Send + 'static>;
|
pub type BodyStream = Box<dyn Stream<Item = Chunk, Error = BoxedError> + Send + 'static>;
|
||||||
|
|
||||||
pub fn wrap_error(e: Error) -> BoxedError {
|
pub fn wrap_error(e: Error) -> BoxedError {
|
||||||
Box::new(e.compat())
|
Box::new(e.compat())
|
||||||
|
@ -265,7 +265,7 @@ pub fn run() -> Result<(), Error> {
|
|||||||
// Start the web interface.
|
// Start the web interface.
|
||||||
let addr = args.flag_http_addr.parse().unwrap();
|
let addr = args.flag_http_addr.parse().unwrap();
|
||||||
let server = ::hyper::server::Server::bind(&addr).tcp_nodelay(true).serve(
|
let server = ::hyper::server::Server::bind(&addr).tcp_nodelay(true).serve(
|
||||||
move || Ok::<_, Box<StdError + Send + Sync>>(s.clone()));
|
move || Ok::<_, Box<dyn StdError + Send + Sync>>(s.clone()));
|
||||||
|
|
||||||
let shutdown = setup_shutdown().shared();
|
let shutdown = setup_shutdown().shared();
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ impl slices::Slice for Slice {
|
|||||||
|
|
||||||
fn end(&self) -> u64 { return self.0 & 0xFF_FF_FF_FF_FF }
|
fn end(&self) -> u64 { return self.0 & 0xFF_FF_FF_FF_FF }
|
||||||
fn get_range(&self, f: &File, range: Range<u64>, len: u64)
|
fn get_range(&self, f: &File, range: Range<u64>, len: u64)
|
||||||
-> Box<Stream<Item = Self::Chunk, Error = BoxedError> + Send> {
|
-> Box<dyn Stream<Item = Self::Chunk, Error = BoxedError> + Send> {
|
||||||
trace!("getting mp4 slice {:?}'s range {:?} / {}", self, range, len);
|
trace!("getting mp4 slice {:?}'s range {:?} / {}", self, range, len);
|
||||||
let p = self.p();
|
let p = self.p();
|
||||||
let res = match self.t() {
|
let res = match self.t() {
|
||||||
@ -1518,7 +1518,7 @@ impl http_serve::Entity for File {
|
|||||||
fn etag(&self) -> Option<HeaderValue> { Some(self.0.etag.clone()) }
|
fn etag(&self) -> Option<HeaderValue> { Some(self.0.etag.clone()) }
|
||||||
fn len(&self) -> u64 { self.0.slices.len() }
|
fn len(&self) -> u64 { self.0.slices.len() }
|
||||||
fn get_range(&self, range: Range<u64>)
|
fn get_range(&self, range: Range<u64>)
|
||||||
-> Box<Stream<Item = Self::Data, Error = Self::Error> + Send> {
|
-> Box<dyn Stream<Item = Self::Data, Error = Self::Error> + Send> {
|
||||||
self.0.slices.get_range(self, range)
|
self.0.slices.get_range(self, range)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ pub trait Slice : fmt::Debug + Sized + Sync + 'static {
|
|||||||
/// The additional argument `ctx` is as supplied to the `Slices`.
|
/// The additional argument `ctx` is as supplied to the `Slices`.
|
||||||
/// The additional argument `l` is the length of this slice, as determined by the `Slices`.
|
/// The additional argument `l` is the length of this slice, as determined by the `Slices`.
|
||||||
fn get_range(&self, ctx: &Self::Ctx, r: Range<u64>, len: u64)
|
fn get_range(&self, ctx: &Self::Ctx, r: Range<u64>, len: u64)
|
||||||
-> Box<Stream<Item = Self::Chunk, Error = BoxedError> + Send>;
|
-> Box<dyn Stream<Item = Self::Chunk, Error = BoxedError> + Send>;
|
||||||
|
|
||||||
fn get_slices(ctx: &Self::Ctx) -> &Slices<Self>;
|
fn get_slices(ctx: &Self::Ctx) -> &Slices<Self>;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ impl<S> Slices<S> where S: Slice {
|
|||||||
/// Writes `range` to `out`.
|
/// Writes `range` to `out`.
|
||||||
/// This interface mirrors `http_serve::Entity::write_to`, with the additional `ctx` argument.
|
/// This interface mirrors `http_serve::Entity::write_to`, with the additional `ctx` argument.
|
||||||
pub fn get_range(&self, ctx: &S::Ctx, range: Range<u64>)
|
pub fn get_range(&self, ctx: &S::Ctx, range: Range<u64>)
|
||||||
-> Box<Stream<Item = S::Chunk, Error = BoxedError> + Send> {
|
-> Box<dyn Stream<Item = S::Chunk, Error = BoxedError> + Send> {
|
||||||
if range.start > range.end || range.end > self.len {
|
if range.start > range.end || range.end > self.len {
|
||||||
return Box::new(stream::once(Err(wrap_error(format_err_t!(
|
return Box::new(stream::once(Err(wrap_error(format_err_t!(
|
||||||
Internal, "Bad range {:?} for slice of length {}", range, self.len)))));
|
Internal, "Bad range {:?} for slice of length {}", range, self.len)))));
|
||||||
@ -176,7 +176,7 @@ mod tests {
|
|||||||
fn end(&self) -> u64 { self.end }
|
fn end(&self) -> u64 { self.end }
|
||||||
|
|
||||||
fn get_range(&self, _ctx: &&'static Slices<FakeSlice>, r: Range<u64>, _l: u64)
|
fn get_range(&self, _ctx: &&'static Slices<FakeSlice>, r: Range<u64>, _l: u64)
|
||||||
-> Box<Stream<Item = FakeChunk, Error = BoxedError> + Send> {
|
-> Box<dyn Stream<Item = FakeChunk, Error = BoxedError> + Send> {
|
||||||
Box::new(stream::once(Ok(FakeChunk{slice: self.name, range: r})))
|
Box::new(stream::once(Ok(FakeChunk{slice: self.name, range: r})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ pub static ROTATE_INTERVAL_SEC: i64 = 60;
|
|||||||
|
|
||||||
/// Common state that can be used by multiple `Streamer` instances.
|
/// Common state that can be used by multiple `Streamer` instances.
|
||||||
pub struct Environment<'a, 'b, C, S> where C: Clocks + Clone, S: 'a + stream::Stream {
|
pub struct Environment<'a, 'b, C, S> where C: Clocks + Clone, S: 'a + stream::Stream {
|
||||||
pub opener: &'a stream::Opener<S>,
|
pub opener: &'a dyn stream::Opener<S>,
|
||||||
pub db: &'b Arc<Database<C>>,
|
pub db: &'b Arc<Database<C>>,
|
||||||
pub shutdown: &'b Arc<AtomicBool>,
|
pub shutdown: &'b Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ pub struct Streamer<'a, C, S> where C: Clocks + Clone, S: 'a + stream::Stream {
|
|||||||
db: Arc<Database<C>>,
|
db: Arc<Database<C>>,
|
||||||
dir: Arc<dir::SampleFileDir>,
|
dir: Arc<dir::SampleFileDir>,
|
||||||
syncer_channel: writer::SyncerChannel<::std::fs::File>,
|
syncer_channel: writer::SyncerChannel<::std::fs::File>,
|
||||||
opener: &'a stream::Opener<S>,
|
opener: &'a dyn stream::Opener<S>,
|
||||||
stream_id: i32,
|
stream_id: i32,
|
||||||
short_name: String,
|
short_name: String,
|
||||||
url: String,
|
url: String,
|
||||||
|
10
src/web.rs
10
src/web.rs
@ -798,7 +798,7 @@ impl Service {
|
|||||||
///
|
///
|
||||||
/// Use with `and_then` to chain logic which consumes the form body.
|
/// Use with `and_then` to chain logic which consumes the form body.
|
||||||
fn with_form_body(&self, mut req: Request<hyper::Body>)
|
fn with_form_body(&self, mut req: Request<hyper::Body>)
|
||||||
-> Box<Future<Item = (Request<hyper::Body>, hyper::Chunk),
|
-> Box<dyn Future<Item = (Request<hyper::Body>, hyper::Chunk),
|
||||||
Error = Response<Body>> +
|
Error = Response<Body>> +
|
||||||
Send + 'static> {
|
Send + 'static> {
|
||||||
if *req.method() != http::method::Method::POST {
|
if *req.method() != http::method::Method::POST {
|
||||||
@ -911,11 +911,11 @@ impl ::hyper::service::Service for Service {
|
|||||||
type ReqBody = ::hyper::Body;
|
type ReqBody = ::hyper::Body;
|
||||||
type ResBody = Body;
|
type ResBody = Body;
|
||||||
type Error = BoxedError;
|
type Error = BoxedError;
|
||||||
type Future = Box<Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send + 'static>;
|
type Future = Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send + 'static>;
|
||||||
|
|
||||||
fn call(&mut self, req: Request<::hyper::Body>) -> Self::Future {
|
fn call(&mut self, req: Request<::hyper::Body>) -> Self::Future {
|
||||||
fn wrap<R>(is_private: bool, r: R)
|
fn wrap<R>(is_private: bool, r: R)
|
||||||
-> Box<Future<Item = Response<Body>, Error = BoxedError> + Send + 'static>
|
-> Box<dyn Future<Item = Response<Body>, Error = BoxedError> + Send + 'static>
|
||||||
where R: Future<Item = Response<Body>, Error = Response<Body>> + Send + 'static {
|
where R: Future<Item = Response<Body>, Error = Response<Body>> + Send + 'static {
|
||||||
return Box::new(r.or_else(|e| Ok(e)).map(move |mut r| {
|
return Box::new(r.or_else(|e| Ok(e)).map(move |mut r| {
|
||||||
if is_private {
|
if is_private {
|
||||||
@ -926,7 +926,7 @@ impl ::hyper::service::Service for Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_r(is_private: bool, r: ResponseResult)
|
fn wrap_r(is_private: bool, r: ResponseResult)
|
||||||
-> Box<Future<Item = Response<Body>, Error = BoxedError> + Send + 'static> {
|
-> Box<dyn Future<Item = Response<Body>, Error = BoxedError> + Send + 'static> {
|
||||||
return wrap(is_private, future::result(r))
|
return wrap(is_private, future::result(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,7 +1009,7 @@ mod tests {
|
|||||||
}).unwrap();
|
}).unwrap();
|
||||||
let server = hyper::server::Server::bind(&addr)
|
let server = hyper::server::Server::bind(&addr)
|
||||||
.tcp_nodelay(true)
|
.tcp_nodelay(true)
|
||||||
.serve(move || Ok::<_, Box<StdError + Send + Sync>>(service.clone()));
|
.serve(move || Ok::<_, Box<dyn StdError + Send + Sync>>(service.clone()));
|
||||||
let addr = server.local_addr(); // resolve port 0 to a real ephemeral port number.
|
let addr = server.local_addr(); // resolve port 0 to a real ephemeral port number.
|
||||||
let handle = ::std::thread::spawn(move || {
|
let handle = ::std::thread::spawn(move || {
|
||||||
::tokio::run(server.with_graceful_shutdown(shutdown_rx).map_err(|e| panic!(e)));
|
::tokio::run(server.with_graceful_shutdown(shutdown_rx).map_err(|e| panic!(e)));
|
||||||
|
Loading…
Reference in New Issue
Block a user