diff --git a/server/db/writer.rs b/server/db/writer.rs index bcb1a7e..24f0f6a 100644 --- a/server/db/writer.rs +++ b/server/db/writer.rs @@ -198,7 +198,7 @@ pub struct NewLimit { /// This is expected to be performed from `moonfire-nvr config` when no syncer is running. /// It potentially flushes the database twice (before and after the actual deletion). pub fn lower_retention( - db: Arc, + db: &Arc, dir_id: i32, limits: &[NewLimit], ) -> Result<(), Error> { diff --git a/server/src/cmds/config/cameras.rs b/server/src/cmds/config/cameras.rs index d80e40d..4aa053d 100644 --- a/server/src/cmds/config/cameras.rs +++ b/server/src/cmds/config/cameras.rs @@ -77,28 +77,28 @@ fn get_camera(siv: &mut Cursive) -> Camera { }; for &t in &db::ALL_STREAM_TYPES { let url = siv - .find_name::(&format!("{}_url", t.as_str())) + .find_name::(&format!("{}_url", t)) .unwrap() .get_content() .as_str() .to_owned(); let record = siv - .find_name::(&format!("{}_record", t.as_str())) + .find_name::(&format!("{}_record", t)) .unwrap() .is_checked(); let rtsp_transport = *siv - .find_name::>(&format!("{}_rtsp_transport", t.as_str())) + .find_name::>(&format!("{}_rtsp_transport", t)) .unwrap() .selection() .unwrap(); let flush_if_sec = siv - .find_name::(&format!("{}_flush_if_sec", t.as_str())) + .find_name::(&format!("{}_flush_if_sec", t)) .unwrap() .get_content() .as_str() .to_owned(); let sample_file_dir_id = *siv - .find_name::>>(&format!("{}_sample_file_dir", t.as_str())) + .find_name::>>(&format!("{}_sample_file_dir", t)) .unwrap() .selection() .unwrap(); @@ -367,9 +367,8 @@ fn confirm_deletion(siv: &mut Cursive, db: &Arc, id: i32, to_delet let l = db.lock(); for (&stream_id, stream) in l.streams_by_id() { if stream.camera_id == id { - let dir_id = match stream.sample_file_dir_id { - Some(d) => d, - None => continue, + let Some(dir_id) = stream.sample_file_dir_id else { + continue }; let l = zero_limits .entry(dir_id) @@ -406,7 +405,7 @@ fn lower_retention( let dirs_to_open: Vec<_> = 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, dir_id, l)?; } Ok(()) } @@ -441,10 +440,7 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option "".to_string(), - Some(id) => id.to_string(), - }), + views::TextView::new(item.map_or_else(|| "".to_string(), |id| id.to_string())), ) .child("uuid", views::TextView::new("").with_name("uuid")) .child("short name", views::EditView::new().with_name("short_name")) @@ -481,18 +477,18 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option(&format!("{}_test", type_.as_str())) + .find_name::(&format!("{}_test", type_)) .unwrap(); edit_stream_url(type_, content, test_button); }) - .with_name(format!("{}_url", type_.as_str())) + .with_name(format!("{}_url", type_)) .full_width(), ) .child(views::DummyView) .child( views::Button::new("Test", move |siv| press_test(siv, type_)) .disabled() - .with_name(format!("{}_test", type_.as_str())), + .with_name(format!("{}_test", type_)), ), ) .child( @@ -500,30 +496,30 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option>::new() .with_all(dirs.iter().map(|(p, id)| (p.display().to_string(), *id))) .popup() - .with_name(format!("{}_sample_file_dir", type_.as_str())), + .with_name(format!("{}_sample_file_dir", type_)), ) .child( "record", - views::Checkbox::new().with_name(format!("{}_record", type_.as_str())), + views::Checkbox::new().with_name(format!("{}_record", type_)), ) .child( "rtsp_transport", views::SelectView::<&str>::new() .with_all([("(default)", ""), ("tcp", "tcp"), ("udp", "udp")]) .popup() - .with_name(format!("{}_rtsp_transport", type_.as_str())), + .with_name(format!("{}_rtsp_transport", type_)), ) .child( "flush_if_sec", - views::EditView::new().with_name(format!("{}_flush_if_sec", type_.as_str())), + views::EditView::new().with_name(format!("{}_flush_if_sec", type_)), ) .child( "usage/capacity", - views::TextView::new("").with_name(format!("{}_usage_cap", type_.as_str())), + views::TextView::new("").with_name(format!("{}_usage_cap", type_)), ) .min_height(5); layout.add_child(views::DummyView); - layout.add_child(views::TextView::new(format!("{} stream", type_.as_str()))); + layout.add_child(views::TextView::new(format!("{} stream", type_))); layout.add_child(list); } @@ -596,14 +592,13 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option>| v.set_selection(selected_dir), ); } @@ -616,8 +611,7 @@ fn edit_camera_dialog(db: &Arc, siv: &mut Cursive, item: &Option, siv: &mut Cursive) { let db = db.clone(); move |siv, item| edit_camera_dialog(&db, siv, item) }) - .item("".to_string(), None) + .item("", None) .with_all( db.lock() .cameras_by_id() diff --git a/server/src/cmds/config/dirs.rs b/server/src/cmds/config/dirs.rs index 40a11c0..a99f9ea 100644 --- a/server/src/cmds/config/dirs.rs +++ b/server/src/cmds/config/dirs.rs @@ -140,7 +140,7 @@ fn actually_delete(model: &RefCell, siv: &mut Cursive) { let mut l = model.db.lock(); l.open_sample_file_dirs(&[model.dir_id]).unwrap(); // TODO: don't unwrap. } - if let Err(e) = writer::lower_retention(model.db.clone(), model.dir_id, &new_limits[..]) { + if let Err(e) = writer::lower_retention(&model.db, model.dir_id, &new_limits[..]) { siv.add_layer( views::Dialog::text(format!("Unable to delete excess video: {e}")) .title("Error") diff --git a/server/src/cmds/config/mod.rs b/server/src/cmds/config/mod.rs index 8fdd2e8..dee4dab 100644 --- a/server/src/cmds/config/mod.rs +++ b/server/src/cmds/config/mod.rs @@ -47,9 +47,9 @@ pub fn run(args: Args) -> Result { views::Dialog::around( views::SelectView::, &mut Cursive)>::new() .on_submit(move |siv, item| item(&db, siv)) - .item("Cameras and streams".to_string(), cameras::top_dialog) - .item("Directories and retention".to_string(), dirs::top_dialog) - .item("Users".to_string(), users::top_dialog), + .item("Cameras and streams", cameras::top_dialog) + .item("Directories and retention", dirs::top_dialog) + .item("Users", users::top_dialog), ) .button("Quit", |siv| siv.quit()) .title("Main menu"), diff --git a/server/src/cmds/config/users.rs b/server/src/cmds/config/users.rs index b025ea9..7948ee5 100644 --- a/server/src/cmds/config/users.rs +++ b/server/src/cmds/config/users.rs @@ -127,9 +127,7 @@ fn edit_user_dialog(db: &Arc, siv: &mut Cursive, item: Option let l = db.lock(); let u = item.map(|id| l.users_by_id().get(&id).unwrap()); username = u.map(|u| u.username.clone()).unwrap_or_default(); - id_str = item - .map(|id| id.to_string()) - .unwrap_or_else(|| "".to_string()); + id_str = item.map_or_else(|| "".to_string(), |id| id.to_string()); has_password = u.map(|u| u.has_password()).unwrap_or(false); permissions = u.map(|u| u.permissions.clone()).unwrap_or_default(); } @@ -138,7 +136,7 @@ fn edit_user_dialog(db: &Arc, siv: &mut Cursive, item: Option .child( "username", views::EditView::new() - .content(username.clone()) + .content(&username) .with_name("username"), ); let mut layout = views::LinearLayout::vertical()