diff --git a/server/base/strutil.rs b/server/base/strutil.rs index 16e57ae..067c9f0 100644 --- a/server/base/strutil.rs +++ b/server/base/strutil.rs @@ -61,6 +61,7 @@ fn decode_size_internal(input: &str) -> IResult<&str, i64> { } /// Decodes a human-readable size as output by encode_size. +#[allow(clippy::result_unit_err)] pub fn decode_size(encoded: &str) -> Result { let (remaining, decoded) = decode_size_internal(encoded).map_err(|_e| ())?; if !remaining.is_empty() { @@ -85,6 +86,7 @@ pub fn hex(raw: &[u8]) -> String { } /// Returns [0, 16) or error. +#[allow(clippy::result_unit_err)] fn dehex_byte(hex_byte: u8) -> Result { match hex_byte { b'0'..=b'9' => Ok(hex_byte - b'0'), @@ -95,6 +97,7 @@ fn dehex_byte(hex_byte: u8) -> Result { /// Returns a 20-byte raw form of the given hex string. /// (This is the size of a SHA1 hash, the only current use of this function.) +#[allow(clippy::result_unit_err)] pub fn dehex(hexed: &[u8]) -> Result<[u8; 20], ()> { if hexed.len() != 40 { return Err(()); diff --git a/server/db/auth.rs b/server/db/auth.rs index 1fb552f..44bc2f8 100644 --- a/server/db/auth.rs +++ b/server/db/auth.rs @@ -92,7 +92,7 @@ impl UserChange { pub fn set_password(&mut self, pwd: String) { let salt = SaltString::generate(&mut scrypt::password_hash::rand_core::OsRng); - let params = PARAMS.lock().clone(); + let params = *PARAMS.lock(); let hash = scrypt::Scrypt .hash_password_customized(pwd.as_bytes(), None, None, params, &salt) .unwrap(); @@ -142,7 +142,7 @@ impl rusqlite::types::FromSql for FromSqlIpAddr { use rusqlite::types::ValueRef; match value { ValueRef::Null => Ok(FromSqlIpAddr(None)), - ValueRef::Blob(ref b) => match b.len() { + ValueRef::Blob(b) => match b.len() { 4 => { let mut buf = [0u8; 4]; buf.copy_from_slice(b); diff --git a/server/db/check.rs b/server/db/check.rs index e03cd3e..01850f6 100644 --- a/server/db/check.rs +++ b/server/db/check.rs @@ -73,7 +73,7 @@ pub fn run(conn: &mut rusqlite::Connection, opts: &Options) -> Result = FnvHashMap::default(); @@ -141,7 +141,7 @@ pub fn run(conn: &mut rusqlite::Connection, opts: &Options) -> Result Stream::default(), - Some(d) => d.remove(&stream_id).unwrap_or_else(Stream::default), + Some(d) => d.remove(&stream_id).unwrap_or_default(), }; stream.cum_recordings = Some(cum_recordings); printed_error |= compare_stream(conn, dir_id, stream_id, opts, stream, &mut ctx)?; diff --git a/server/db/compare.rs b/server/db/compare.rs index 97384d0..08885bf 100644 --- a/server/db/compare.rs +++ b/server/db/compare.rs @@ -67,12 +67,12 @@ fn diff_slices( match item { diff::Result::Left(i) => { changed = true; - write!(&mut diff, "-{}\n", i) + writeln!(&mut diff, "-{}", i) } - diff::Result::Both(i, _) => write!(&mut diff, " {}\n", i), + diff::Result::Both(i, _) => writeln!(&mut diff, " {}", i), diff::Result::Right(i) => { changed = true; - write!(&mut diff, "+{}\n", i) + writeln!(&mut diff, "+{}", i) } } .unwrap(); @@ -177,8 +177,8 @@ pub fn get_diffs( // Compare columns and indices for each table. for t in &tables1 { - let columns1 = get_table_columns(c1, &t)?; - let columns2 = get_table_columns(c2, &t)?; + let columns1 = get_table_columns(c1, t)?; + let columns2 = get_table_columns(c2, t)?; if let Some(diff) = diff_slices(n1, &columns1[..], n2, &columns2[..]) { write!( &mut diffs, @@ -187,8 +187,8 @@ pub fn get_diffs( )?; } - let mut indices1 = get_indices(c1, &t)?; - let mut indices2 = get_indices(c2, &t)?; + let mut indices1 = get_indices(c1, t)?; + let mut indices2 = get_indices(c2, t)?; indices1.sort_by(|a, b| a.name.cmp(&b.name)); indices2.sort_by(|a, b| a.name.cmp(&b.name)); if let Some(diff) = diff_slices(n1, &indices1[..], n2, &indices2[..]) { diff --git a/server/db/db.rs b/server/db/db.rs index a3990ae..83121a0 100644 --- a/server/db/db.rs +++ b/server/db/db.rs @@ -2113,7 +2113,7 @@ impl LockedDatabase { /// /// These are `pub` so that the `moonfire-nvr sql` command can pass to the SQLite3 binary with /// `-cmd`. -pub static INTEGRITY_PRAGMAS: [&'static str; 3] = [ +pub static INTEGRITY_PRAGMAS: [&str; 3] = [ // Enforce foreign keys. This is on by default with --features=bundled (as rusqlite // 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 diff --git a/server/db/dir/mod.rs b/server/db/dir/mod.rs index 280c70d..a622bf2 100644 --- a/server/db/dir/mod.rs +++ b/server/db/dir/mod.rs @@ -156,7 +156,7 @@ pub(crate) fn read_meta(dir: &Fd) -> Result { ); } let data = &data[pos..pos + len as usize]; - let mut s = protobuf::CodedInputStream::from_bytes(&data); + let mut s = protobuf::CodedInputStream::from_bytes(data); meta.merge_from(&mut s) .map_err(|e| e.context("Unable to parse metadata proto"))?; Ok(meta) diff --git a/server/db/json.rs b/server/db/json.rs index 0c6d131..93cf54c 100644 --- a/server/db/json.rs +++ b/server/db/json.rs @@ -239,7 +239,7 @@ pub struct StreamConfig { } sql!(StreamConfig); -pub const STREAM_MODE_RECORD: &'static str = "record"; +pub const STREAM_MODE_RECORD: &str = "record"; impl StreamConfig { pub fn is_empty(&self) -> bool { diff --git a/server/db/recording.rs b/server/db/recording.rs index 5ee3934..24cb2e1 100644 --- a/server/db/recording.rs +++ b/server/db/recording.rs @@ -374,6 +374,7 @@ impl Segment { // Note: this inner loop avoids ? for performance. Don't change these lines without // reading https://github.com/rust-lang/rust/issues/37939 and running // mp4::bench::build_index. + #[allow(clippy::question_mark)] if let Err(e) = f(&it) { return Err(e); } diff --git a/server/db/signal.rs b/server/db/signal.rs index 330b9b7..09b9dad 100644 --- a/server/db/signal.rs +++ b/server/db/signal.rs @@ -344,7 +344,7 @@ impl State { } match self.signals_by_id.get(&signal) { None => bail_t!(InvalidArgument, "unknown signal {}", signal), - Some(ref s) => { + Some(s) => { let states = self .types_by_uuid .get(&s.type_) diff --git a/server/db/upgrade/mod.rs b/server/db/upgrade/mod.rs index 36a0b54..58d0690 100644 --- a/server/db/upgrade/mod.rs +++ b/server/db/upgrade/mod.rs @@ -76,7 +76,7 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res for ver in old_ver..target_ver { info!("...from version {} to version {}", ver, ver + 1); let tx = conn.transaction()?; - upgraders[ver as usize](&args, &tx)?; + upgraders[ver as usize](args, &tx)?; tx.execute( r#" insert into version (id, unix_time, notes) @@ -94,7 +94,7 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> { db::check_sqlite_version()?; db::set_integrity_pragmas(conn)?; - set_journal_mode(&conn, args.preset_journal)?; + set_journal_mode(conn, args.preset_journal)?; upgrade(args, db::EXPECTED_VERSION, conn)?; // As in "moonfire-nvr init": try for page_size=16384 and wal for the reasons explained there. @@ -114,7 +114,7 @@ pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> { )?; } - set_journal_mode(&conn, "wal")?; + set_journal_mode(conn, "wal")?; info!("...done."); Ok(()) diff --git a/server/db/upgrade/v0_to_v1.rs b/server/db/upgrade/v0_to_v1.rs index 5bca566..77fcf3a 100644 --- a/server/db/upgrade/v0_to_v1.rs +++ b/server/db/upgrade/v0_to_v1.rs @@ -221,7 +221,7 @@ fn update_camera( update camera set next_recording_id = :next_recording_id where id = :id "#, )?; - for (ref id, ref state) in &camera_state { + for (ref id, state) in &camera_state { stmt.execute(named_params! { ":id": &id, ":next_recording_id": &state.next_recording_id, diff --git a/server/db/upgrade/v1_to_v2.rs b/server/db/upgrade/v1_to_v2.rs index 233f0f0..5d727b4 100644 --- a/server/db/upgrade/v1_to_v2.rs +++ b/server/db/upgrade/v1_to_v2.rs @@ -97,7 +97,7 @@ pub fn run(args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> meta.dir_uuid.extend_from_slice(dir_uuid_bytes); let open = meta.last_complete_open.mut_or_insert_default(); open.id = open_id; - open.uuid.extend_from_slice(&open_uuid_bytes); + open.uuid.extend_from_slice(open_uuid_bytes); } dir::write_meta(d.as_raw_fd(), &meta)?; diff --git a/server/db/upgrade/v2_to_v3.rs b/server/db/upgrade/v2_to_v3.rs index db7f4f5..a108da2 100644 --- a/server/db/upgrade/v2_to_v3.rs +++ b/server/db/upgrade/v2_to_v3.rs @@ -55,7 +55,7 @@ fn open_sample_file_dir(tx: &rusqlite::Transaction) -> Result Result<(), Error> { - let d = open_sample_file_dir(&tx)?; + let d = open_sample_file_dir(tx)?; let mut stmt = tx.prepare( r#" select diff --git a/server/db/upgrade/v4_to_v5.rs b/server/db/upgrade/v4_to_v5.rs index 9f2a855..fb61523 100644 --- a/server/db/upgrade/v4_to_v5.rs +++ b/server/db/upgrade/v4_to_v5.rs @@ -37,7 +37,7 @@ fn maybe_upgrade_meta(dir: &dir::Fd, db_meta: &schema::DirMeta) -> Result Syncer { let timeout = (t - now) .to_std() .unwrap_or_else(|_| StdDuration::new(0, 0)); - match self.db.clocks().recv_timeout(&cmds, timeout) { + match self.db.clocks().recv_timeout(cmds, timeout) { Err(mpsc::RecvTimeoutError::Disconnected) => return false, // cmd senders gone. Err(mpsc::RecvTimeoutError::Timeout) => { self.flush(); diff --git a/server/src/cmds/config/cameras.rs b/server/src/cmds/config/cameras.rs index 1837ef1..ffdf42c 100644 --- a/server/src/cmds/config/cameras.rs +++ b/server/src/cmds/config/cameras.rs @@ -118,12 +118,8 @@ fn parse_url(raw: &str, allowed_schemes: &'static [&'static str]) -> Result = zero_limits.keys().copied().collect(); db.lock().open_sample_file_dirs(&dirs_to_open[..])?; for (&dir_id, l) in &zero_limits { - writer::lower_retention(db.clone(), dir_id, &l)?; + writer::lower_retention(db.clone(), dir_id, l)?; } Ok(()) } @@ -557,7 +553,7 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option(&format!("{}_test", t.as_str())) .unwrap(); edit_url( - &s.config.url.as_ref().map(Url::as_str).unwrap_or(""), + s.config.url.as_ref().map(Url::as_str).unwrap_or(""), test_button, ); dialog.call_on_name( @@ -596,7 +592,7 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option Result { let sa: SocketAddr = match addr { - config::AddressConfig::Ipv4(a) => a.clone().into(), - config::AddressConfig::Ipv6(a) => a.clone().into(), + config::AddressConfig::Ipv4(a) => (*a).into(), + config::AddressConfig::Ipv6(a) => (*a).into(), config::AddressConfig::Unix(p) => { prepare_unix_socket(p); return Ok(Listener::Unix( @@ -390,7 +390,7 @@ async fn inner( let web_handles = web_handles?; info!("Ready to serve HTTP requests"); - let _ = shutdown_rx.as_future().await; + shutdown_rx.as_future().await; info!("Shutting down streamers and syncers."); tokio::task::spawn_blocking({ diff --git a/server/src/cmds/sql.rs b/server/src/cmds/sql.rs index 4a42e4b..aa376b6 100644 --- a/server/src/cmds/sql.rs +++ b/server/src/cmds/sql.rs @@ -52,12 +52,7 @@ pub fn run(args: Args) -> Result { db.push("?mode=ro"); } Err(Command::new("sqlite3") - .args( - db::db::INTEGRITY_PRAGMAS - .iter() - .map(|p| ["-cmd", p]) - .flatten(), - ) + .args(db::db::INTEGRITY_PRAGMAS.iter().flat_map(|p| ["-cmd", p])) .arg(&db) .args(&args.arg) .exec() diff --git a/server/src/json.rs b/server/src/json.rs index a6d5e6a..c00adf0 100644 --- a/server/src/json.rs +++ b/server/src/json.rs @@ -446,7 +446,7 @@ impl<'a> ListRecordings<'a> { for id in v { map.serialize_entry( id, - &VideoSampleEntry::from(&db.video_sample_entries_by_id().get(id).unwrap()), + &VideoSampleEntry::from(db.video_sample_entries_by_id().get(id).unwrap()), )?; } map.end() diff --git a/server/src/mp4.rs b/server/src/mp4.rs index bd1c4e5..44c0103 100644 --- a/server/src/mp4.rs +++ b/server/src/mp4.rs @@ -801,7 +801,7 @@ impl slices::Slice for Slice { SliceType::Stsz => self.wrap_index(f, range.clone(), len, &Segment::stsz), SliceType::Stss => self.wrap_index(f, range.clone(), len, &Segment::stss), SliceType::Co64 => f.0.get_co64(range.clone(), len), - SliceType::VideoSampleData => return f.0.get_video_sample_data(p, range.clone()), + SliceType::VideoSampleData => return f.0.get_video_sample_data(p, range), SliceType::SubtitleSampleData => f.0.get_subtitle_sample_data(p, range.clone(), len), SliceType::Truns => self.wrap_truns(f, range.clone(), len as usize), }; diff --git a/server/src/web/mod.rs b/server/src/web/mod.rs index 532a15d..6ef6ce8 100644 --- a/server/src/web/mod.rs +++ b/server/src/web/mod.rs @@ -98,7 +98,7 @@ struct Caller { type ResponseResult = Result, HttpError>; fn serve_json(req: &Request, out: &T) -> ResponseResult { - let (mut resp, writer) = http_serve::streaming_body(&req).build(); + let (mut resp, writer) = http_serve::streaming_body(req).build(); resp.headers_mut().insert( header::CONTENT_TYPE, HeaderValue::from_static("application/json"), diff --git a/server/src/web/path.rs b/server/src/web/path.rs index 351c344..d4f8102 100644 --- a/server/src/web/path.rs +++ b/server/src/web/path.rs @@ -50,10 +50,10 @@ impl Path { Some(p) => p, None => return Path::NotFound, }; - if let Ok(id) = i32::from_str(&path) { + if let Ok(id) = i32::from_str(path) { return Path::InitSegment(id, debug); } - return Path::NotFound; + Path::NotFound } else if let Some(path) = path.strip_prefix("cameras/") { let (uuid, path) = match path.split_once('/') { Some(pair) => pair, diff --git a/server/src/web/session.rs b/server/src/web/session.rs index 33cb38c..88100d1 100644 --- a/server/src/web/session.rs +++ b/server/src/web/session.rs @@ -53,7 +53,7 @@ impl Service { 0 }; let (sid, _) = l - .login_by_password(authreq, &r.username, r.password, Some(domain), flags) + .login_by_password(authreq, r.username, r.password, Some(domain), flags) .map_err(|e| plain_response(StatusCode::UNAUTHORIZED, e.to_string()))?; let cookie = encode_sid(sid, flags); Ok(Response::builder()