mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-24 19:46:17 -05:00
clean up the easy clippy errors
I'm still not running clippy on CI and probably should. There are a few left that were a little more involved to address.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -73,7 +73,7 @@ pub fn run(conn: &mut rusqlite::Connection, opts: &Options) -> Result<i32, Error
|
||||
warn!("The following analysis may be incorrect or encounter errors due to schema differences.");
|
||||
}
|
||||
|
||||
let (db_uuid, _config) = raw::read_meta(&conn)?;
|
||||
let (db_uuid, _config) = raw::read_meta(conn)?;
|
||||
|
||||
// Scan directories.
|
||||
let mut dirs_by_id: FnvHashMap<i32, Dir> = FnvHashMap::default();
|
||||
@@ -141,7 +141,7 @@ pub fn run(conn: &mut rusqlite::Connection, opts: &Options) -> Result<i32, Error
|
||||
let cum_recordings = row.get(2)?;
|
||||
let mut stream = match dirs_by_id.get_mut(&dir_id) {
|
||||
None => 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)?;
|
||||
|
||||
@@ -67,12 +67,12 @@ fn diff_slices<T: std::fmt::Display + PartialEq>(
|
||||
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[..]) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -156,7 +156,7 @@ pub(crate) fn read_meta(dir: &Fd) -> Result<schema::DirMeta, Error> {
|
||||
);
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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_)
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ fn open_sample_file_dir(tx: &rusqlite::Transaction) -> Result<Arc<dir::SampleFil
|
||||
}
|
||||
|
||||
pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> {
|
||||
let d = open_sample_file_dir(&tx)?;
|
||||
let d = open_sample_file_dir(tx)?;
|
||||
let mut stmt = tx.prepare(
|
||||
r#"
|
||||
select
|
||||
|
||||
@@ -37,7 +37,7 @@ fn maybe_upgrade_meta(dir: &dir::Fd, db_meta: &schema::DirMeta) -> Result<bool,
|
||||
dir_meta
|
||||
.merge_from(&mut s)
|
||||
.map_err(|e| e.context("Unable to parse metadata proto: {}"))?;
|
||||
if let Err(e) = dir::SampleFileDir::check_consistent(&db_meta, &dir_meta) {
|
||||
if let Err(e) = dir::SampleFileDir::check_consistent(db_meta, &dir_meta) {
|
||||
bail!(
|
||||
"Inconsistent db_meta={:?} dir_meta={:?}: {}",
|
||||
&db_meta,
|
||||
|
||||
@@ -432,7 +432,7 @@ impl<C: Clocks + Clone, D: DirWriter> Syncer<C, D> {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user