Fix clippy warmings
This commit is contained in:
parent
1ea0ea2ed1
commit
171d051710
|
@ -1,6 +1,5 @@
|
||||||
|
use log::info;
|
||||||
use peach_lib::dyndns_client::dyndns_update_ip;
|
use peach_lib::dyndns_client::dyndns_update_ip;
|
||||||
use log::{info};
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// initalize the logger
|
// initalize the logger
|
||||||
|
|
|
@ -72,11 +72,8 @@ fn save_peach_config(peach_config: PeachConfig) -> Result<PeachConfig, PeachErro
|
||||||
pub fn load_peach_config() -> Result<PeachConfig, PeachError> {
|
pub fn load_peach_config() -> Result<PeachConfig, PeachError> {
|
||||||
let peach_config_exists = std::path::Path::new(YAML_PATH).exists();
|
let peach_config_exists = std::path::Path::new(YAML_PATH).exists();
|
||||||
|
|
||||||
let peach_config: PeachConfig;
|
let peach_config: PeachConfig = if !peach_config_exists {
|
||||||
|
PeachConfig {
|
||||||
// if this is the first time loading peach_config, we can create a default here
|
|
||||||
if !peach_config_exists {
|
|
||||||
peach_config = PeachConfig {
|
|
||||||
external_domain: "".to_string(),
|
external_domain: "".to_string(),
|
||||||
dyn_domain: "".to_string(),
|
dyn_domain: "".to_string(),
|
||||||
dyn_dns_server_address: DEFAULT_DYN_SERVER_ADDRESS.to_string(),
|
dyn_dns_server_address: DEFAULT_DYN_SERVER_ADDRESS.to_string(),
|
||||||
|
@ -87,7 +84,7 @@ pub fn load_peach_config() -> Result<PeachConfig, PeachError> {
|
||||||
ssb_admin_ids: Vec::new(),
|
ssb_admin_ids: Vec::new(),
|
||||||
admin_password_hash: "".to_string(),
|
admin_password_hash: "".to_string(),
|
||||||
temporary_password_hash: "".to_string(),
|
temporary_password_hash: "".to_string(),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
// otherwise we load peach config from disk
|
// otherwise we load peach config from disk
|
||||||
else {
|
else {
|
||||||
|
@ -95,8 +92,8 @@ pub fn load_peach_config() -> Result<PeachConfig, PeachError> {
|
||||||
source,
|
source,
|
||||||
path: YAML_PATH.to_string(),
|
path: YAML_PATH.to_string(),
|
||||||
})?;
|
})?;
|
||||||
peach_config = serde_yaml::from_str(&contents)?;
|
serde_yaml::from_str(&contents)?
|
||||||
}
|
};
|
||||||
|
|
||||||
Ok(peach_config)
|
Ok(peach_config)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,8 @@
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
fs::OpenOptions,
|
fs::OpenOptions,
|
||||||
fs::File,
|
|
||||||
io::Write,
|
io::Write,
|
||||||
process::{Command, Stdio},
|
process::{Command},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
@ -212,7 +211,7 @@ pub fn get_num_seconds_since_successful_dns_update() -> Result<Option<i64>, Peac
|
||||||
})?;
|
})?;
|
||||||
// replace newline if found
|
// replace newline if found
|
||||||
// TODO: maybe we can use `.trim()` instead
|
// TODO: maybe we can use `.trim()` instead
|
||||||
let contents = contents.replace("\n", "");
|
let contents = contents.replace('\n', "");
|
||||||
// TODO: consider adding additional context?
|
// TODO: consider adding additional context?
|
||||||
let time_ran_dt = DateTime::parse_from_rfc3339(&contents).map_err(|source| {
|
let time_ran_dt = DateTime::parse_from_rfc3339(&contents).map_err(|source| {
|
||||||
PeachError::ParseDateTime {
|
PeachError::ParseDateTime {
|
||||||
|
@ -235,16 +234,15 @@ pub fn is_dns_updater_online() -> Result<bool, PeachError> {
|
||||||
let is_enabled = peach_config.dyn_enabled;
|
let is_enabled = peach_config.dyn_enabled;
|
||||||
// then check if it has successfully run within the last 6 minutes (60*6 seconds)
|
// 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 num_seconds_since_successful_update = get_num_seconds_since_successful_dns_update()?;
|
||||||
let ran_recently: bool;
|
let ran_recently: bool = match num_seconds_since_successful_update {
|
||||||
match num_seconds_since_successful_update {
|
|
||||||
Some(seconds) => {
|
Some(seconds) => {
|
||||||
ran_recently = seconds < (60 * 6);
|
seconds < (60 * 6)
|
||||||
}
|
}
|
||||||
// if the value is None, then the last time it ran successfully is unknown
|
// if the value is None, then the last time it ran successfully is unknown
|
||||||
None => {
|
None => {
|
||||||
ran_recently = false;
|
false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
// debug log
|
// debug log
|
||||||
info!("is_dyndns_enabled: {:?}", is_enabled);
|
info!("is_dyndns_enabled: {:?}", is_enabled);
|
||||||
info!("dyndns_ran_recently: {:?}", ran_recently);
|
info!("dyndns_ran_recently: {:?}", ran_recently);
|
||||||
|
|
Loading…
Reference in New Issue