From 171d05171013c771320d21384c5260ca1c38edb3 Mon Sep 17 00:00:00 2001 From: notplants Date: Tue, 11 Jan 2022 18:06:51 -0500 Subject: [PATCH] Fix clippy warmings --- peach-dyndns-updater/src/main.rs | 5 ++--- peach-lib/src/config_manager.rs | 13 +++++-------- peach-lib/src/dyndns_client.rs | 14 ++++++-------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/peach-dyndns-updater/src/main.rs b/peach-dyndns-updater/src/main.rs index fbbc33a..ecde150 100644 --- a/peach-dyndns-updater/src/main.rs +++ b/peach-dyndns-updater/src/main.rs @@ -1,6 +1,5 @@ +use log::info; use peach_lib::dyndns_client::dyndns_update_ip; -use log::{info}; - fn main() { // initalize the logger @@ -9,4 +8,4 @@ fn main() { info!("Running peach-dyndns-updater"); let result = dyndns_update_ip(); info!("result: {:?}", result); -} \ No newline at end of file +} diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 00fd104..3043b29 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -72,11 +72,8 @@ fn save_peach_config(peach_config: PeachConfig) -> Result Result { let peach_config_exists = std::path::Path::new(YAML_PATH).exists(); - let peach_config: PeachConfig; - - // if this is the first time loading peach_config, we can create a default here - if !peach_config_exists { - peach_config = PeachConfig { + let peach_config: PeachConfig = if !peach_config_exists { + PeachConfig { external_domain: "".to_string(), dyn_domain: "".to_string(), dyn_dns_server_address: DEFAULT_DYN_SERVER_ADDRESS.to_string(), @@ -87,7 +84,7 @@ pub fn load_peach_config() -> Result { ssb_admin_ids: Vec::new(), admin_password_hash: "".to_string(), temporary_password_hash: "".to_string(), - }; + } } // otherwise we load peach config from disk else { @@ -95,8 +92,8 @@ pub fn load_peach_config() -> Result { source, path: YAML_PATH.to_string(), })?; - peach_config = serde_yaml::from_str(&contents)?; - } + serde_yaml::from_str(&contents)? + }; Ok(peach_config) } diff --git a/peach-lib/src/dyndns_client.rs b/peach-lib/src/dyndns_client.rs index 1698ad0..3e66222 100644 --- a/peach-lib/src/dyndns_client.rs +++ b/peach-lib/src/dyndns_client.rs @@ -12,9 +12,8 @@ use std::{ fs, fs::OpenOptions, - fs::File, io::Write, - process::{Command, Stdio}, + process::{Command}, str::FromStr, }; use std::ffi::OsStr; @@ -212,7 +211,7 @@ pub fn get_num_seconds_since_successful_dns_update() -> Result, Peac })?; // replace newline if found // TODO: maybe we can use `.trim()` instead - let contents = contents.replace("\n", ""); + let contents = contents.replace('\n', ""); // TODO: consider adding additional context? let time_ran_dt = DateTime::parse_from_rfc3339(&contents).map_err(|source| { PeachError::ParseDateTime { @@ -235,16 +234,15 @@ pub fn is_dns_updater_online() -> Result { let is_enabled = peach_config.dyn_enabled; // then check if it has successfully run within the last 6 minutes (60*6 seconds) let num_seconds_since_successful_update = get_num_seconds_since_successful_dns_update()?; - let ran_recently: bool; - match num_seconds_since_successful_update { + let ran_recently: bool = match num_seconds_since_successful_update { Some(seconds) => { - ran_recently = seconds < (60 * 6); + seconds < (60 * 6) } // if the value is None, then the last time it ran successfully is unknown None => { - ran_recently = false; + false } - } + }; // debug log info!("is_dyndns_enabled: {:?}", is_enabled); info!("dyndns_ran_recently: {:?}", ran_recently);