diff --git a/src/command_runner.rs b/src/command_runner.rs index 0b17ad0..b4e0956 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -106,7 +106,7 @@ impl<'a> TempSetEnv<'a> { } } -impl<'a> Drop for TempSetEnv<'a> { +impl Drop for TempSetEnv<'_> { fn drop(&mut self) { match self.old_value { Some(ref val) => env::set_var(self.name, val), @@ -115,7 +115,7 @@ impl<'a> Drop for TempSetEnv<'a> { } } -impl<'a, U: AsRef, C: CommandRunner> CommandRunner for SetuidCommandRunner<'a, U, C> { +impl, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> { fn run_with_args_and_stdin( &self, program: &str, @@ -125,8 +125,8 @@ impl<'a, U: AsRef, C: CommandRunner> CommandRunner for SetuidCommandRunner< let uid = get_user_by_name(self.user_name.as_ref()) .expect("User does not exist") .uid(); - let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref())); - let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid)); + let _set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref())); + let _set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid)); //println!("{} {:?}", program, args); let mut child = Command::new(program) .args(args) diff --git a/src/factory.rs b/src/factory.rs index 71aabfc..e529c44 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -21,7 +21,7 @@ pub struct Factory {} impl Factory { pub fn new() -> Self { - Default::default() + Self::default() } pub fn get_repo<'a, CR: CommandRunner>( @@ -87,15 +87,15 @@ impl<'a, C: CommandRunner> SymbolRepository<'a> matches[1].to_string(), self.command_runner, )), - ])) as Box + ])) } else if let Some(matches) = self.home.captures(value) { Box::new(User::new( matches[1].to_string().into(), self.command_runner, &self.user_adder, - )) as Box + )) } else { - Box::new(Dir::new(value.to_string())) as Box + Box::new(Dir::new(value.to_string())) }) } "file" => { @@ -104,17 +104,17 @@ impl<'a, C: CommandRunner> SymbolRepository<'a> Some(Box::new(TlsCsr::new( matches[1].to_string().into(), self.command_runner, - )) as Box) + ))) } else if let Some(matches) = self.private_key.captures(value) { Some(Box::new(TlsKey::new( matches[1].to_string().into(), self.command_runner, - )) as Box) + ))) } else if let Some(matches) = self.systemd_linger.captures(value) { Some(Box::new(SystemdUserSession::new( matches[1].to_string(), self.command_runner, - )) as Box) + ))) } else { None } diff --git a/src/lib.rs b/src/lib.rs index dcc5a68..57ed75b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,29 @@ -// rustfmt - #![deny( + macro_use_extern_crate, + meta_variable_misuse, + non_ascii_idents, trivial_numeric_casts, + unused, + unreachable_pub, unsafe_code, unstable_features, - unused_extern_crates, - unused_import_braces, - unused_qualifications, variant_size_differences, - clippy::use_self + rust_2018_idioms, + future_incompatible, + clippy::cargo, + clippy::nursery, + clippy::pedantic )] -#![warn(unused_results)] -/* -#![warn(missing_docs, trivial_casts, -missing_copy_implementations, -missing_debug_implementations +#![allow( + single_use_lifetimes, + trivial_casts, + clippy::module_name_repetitions, + clippy::cargo_common_metadata, + rustdoc, + missing_docs, + missing_copy_implementations, + missing_debug_implementations )] -*/ -#![allow(box_pointers)] #[macro_use] mod for_each_tuple; diff --git a/src/loggers.rs b/src/loggers.rs index 0569c28..71b928f 100644 --- a/src/loggers.rs +++ b/src/loggers.rs @@ -27,7 +27,7 @@ impl<'a> FilteringLogger<'a> { } } -impl<'a> Logger for FilteringLogger<'a> { +impl Logger for FilteringLogger<'_> { fn debug(&mut self, _str: &str) {} fn write(&mut self, str: &str) { self.logger.write(str) diff --git a/src/schema.rs b/src/schema.rs index 7f12f9c..9fe811c 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -15,14 +15,14 @@ pub enum SymbolRunError { impl Error for SymbolRunError { fn description(&self) -> &str { match self { - SymbolRunError::Symbol(_) => "Symbol execution error", - SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol", + Self::Symbol(_) => "Symbol execution error", + Self::ExecuteDidNotReach(_) => "Target not reached after executing symbol", } } fn cause(&self) -> Option<&dyn Error> { match self { - SymbolRunError::Symbol(ref e) => Some(&**e), - SymbolRunError::ExecuteDidNotReach(_) => None, + Self::Symbol(ref e) => Some(&**e), + Self::ExecuteDidNotReach(_) => None, } } } @@ -30,8 +30,8 @@ impl Error for SymbolRunError { impl fmt::Display for SymbolRunError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - SymbolRunError::Symbol(ref e) => write!(f, "{}", e), - SymbolRunError::ExecuteDidNotReach(_) => write!(f, "{}", self.description()), + Self::Symbol(ref e) => write!(f, "{}", e), + Self::ExecuteDidNotReach(_) => write!(f, "{}", self.description()), } } } @@ -119,13 +119,10 @@ where let mut logger = self.1.borrow_mut(); logger.debug(format!("Running symbol {}", symbol).as_str()); let res = self.0.run_symbol(symbol); - match res { - Err(ref e) => { - logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str()); - } - Ok(_) => { - logger.debug(format!("Successfully finished {}", symbol).as_str()); - } + if let Err(ref e) = res { + logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str()) + } else { + logger.debug(format!("Successfully finished {}", symbol).as_str()) } res } diff --git a/src/storage.rs b/src/storage.rs index 197884b..ea22765 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -13,7 +13,7 @@ pub trait Storage { pub struct SimpleStorage(String, String); impl SimpleStorage { - pub fn new(base: String, filename: String) -> Self { + pub const fn new(base: String, filename: String) -> Self { Self(base, filename) } diff --git a/src/symbols/acme/account_key.rs b/src/symbols/acme/account_key.rs index dc1fac4..988ee79 100644 --- a/src/symbols/acme/account_key.rs +++ b/src/symbols/acme/account_key.rs @@ -24,13 +24,13 @@ impl<'a, P: AsRef, C: CommandRunner> AcmeAccountKey<'a, P, C> { } } -impl<'a, P: AsRef, C: CommandRunner> fmt::Display for AcmeAccountKey<'a, P, C> { +impl, C: CommandRunner> fmt::Display for AcmeAccountKey<'_, P, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "AcmeAccountKey {}", self.path.as_ref().display()) } } -impl<'a, P: AsRef, C: CommandRunner> Symbol for AcmeAccountKey<'a, P, C> { +impl, C: CommandRunner> Symbol for AcmeAccountKey<'_, P, C> { fn target_reached(&self) -> Result> { if !self.path.as_ref().exists() { return Ok(false); @@ -46,7 +46,7 @@ impl<'a, P: AsRef, C: CommandRunner> Symbol for AcmeAccountKey<'a, P, C> { "-text", ], )?; - Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) + Ok(stdout.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) } fn execute(&self) -> Result<(), Box> { diff --git a/src/symbols/acme/cert.rs b/src/symbols/acme/cert.rs index cb6f22e..2af81b4 100644 --- a/src/symbols/acme/cert.rs +++ b/src/symbols/acme/cert.rs @@ -51,8 +51,8 @@ impl<'a, D: AsRef, R: AsRef, C: CommandRunner, K: AsRef, CH: As } } -impl<'a, D: AsRef, R: AsRef, C: CommandRunner, K: AsRef, CH: AsRef> - fmt::Display for AcmeCert<'a, D, R, C, K, CH> +impl, R: AsRef, C: CommandRunner, K: AsRef, CH: AsRef> fmt::Display + for AcmeCert<'_, D, R, C, K, CH> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "AcmeCert {}", self.domain.as_ref()) @@ -61,8 +61,8 @@ impl<'a, D: AsRef, R: AsRef, C: CommandRunner, K: AsRef, CH: As const DAYS_IN_SECONDS: u32 = 24 * 60 * 60; -impl<'a, D: AsRef, R: AsRef, C: CommandRunner, K: AsRef, CH: AsRef> Symbol - for AcmeCert<'a, D, R, C, K, CH> +impl, R: AsRef, C: CommandRunner, K: AsRef, CH: AsRef> Symbol + for AcmeCert<'_, D, R, C, K, CH> { fn target_reached(&self) -> Result> { if !self.get_cert_path().exists() { diff --git a/src/symbols/acme/chain.rs b/src/symbols/acme/chain.rs index e9a2344..d62eb9b 100644 --- a/src/symbols/acme/chain.rs +++ b/src/symbols/acme/chain.rs @@ -32,9 +32,7 @@ impl<'a, D: AsRef, R: AsRef, C: CommandRunner> AcmeCertChain<'a, D, R } } -impl<'a, D: AsRef, R: AsRef, C: CommandRunner> fmt::Display - for AcmeCertChain<'a, D, R, C> -{ +impl, R: AsRef, C: CommandRunner> fmt::Display for AcmeCertChain<'_, D, R, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "AcmeCertChain {}", self.domain.as_ref()) } @@ -42,7 +40,7 @@ impl<'a, D: AsRef, R: AsRef, C: CommandRunner> fmt::Display const DAYS_IN_SECONDS: u32 = 24 * 60 * 60; -impl<'a, D: AsRef, R: AsRef, C: CommandRunner> Symbol for AcmeCertChain<'a, D, R, C> { +impl, R: AsRef, C: CommandRunner> Symbol for AcmeCertChain<'_, D, R, C> { fn target_reached(&self) -> Result> { if !self.get_cert_chain_path().exists() { return Ok(false); diff --git a/src/symbols/acme/mod.rs b/src/symbols/acme/mod.rs index 477de9c..556ec82 100644 --- a/src/symbols/acme/mod.rs +++ b/src/symbols/acme/mod.rs @@ -41,7 +41,7 @@ impl<'a, U: Clone + AsRef, H: AsRef, C: AsRef, R: CommandRunner> acme_command_runner, } } - pub fn get_challenges_dir(&'a self) -> Cow { + pub fn get_challenges_dir(&'a self) -> Cow<'_, Path> { [self.home_dir.as_ref(), "challenges".as_ref()] .iter() .collect::() diff --git a/src/symbols/cron.rs b/src/symbols/cron.rs index 492e5b4..952db93 100644 --- a/src/symbols/cron.rs +++ b/src/symbols/cron.rs @@ -21,7 +21,7 @@ impl<'r, U: AsRef, R: CommandRunner> Cron<'r, String, U, R> { } } -impl<'r, C: AsRef, U: AsRef, R: CommandRunner> Symbol for Cron<'r, C, U, R> { +impl, U: AsRef, R: CommandRunner> Symbol for Cron<'_, C, U, R> { fn target_reached(&self) -> Result> { let tab = self .command_runner @@ -53,7 +53,7 @@ impl<'r, C: AsRef, U: AsRef, R: CommandRunner> Symbol for Cron<'r, C, } } -impl<'r, C: AsRef, U: AsRef, R: CommandRunner> fmt::Display for Cron<'r, C, U, R> { +impl, U: AsRef, R: CommandRunner> fmt::Display for Cron<'_, C, U, R> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "Cron {}", self.user.as_ref()) } diff --git a/src/symbols/factory.rs b/src/symbols/factory.rs index 2eb5829..69d79da 100644 --- a/src/symbols/factory.rs +++ b/src/symbols/factory.rs @@ -17,7 +17,7 @@ use crate::symbols::stored_directory::{StorageDirection, StoredDirectory}; use crate::symbols::systemd::reload::ReloadService; use crate::symbols::systemd::user_service::UserService; use crate::symbols::tls::SelfSignedTlsCert; -use crate::symbols::{Symbol, SymbolRunner}; +use crate::symbols::Symbol; pub trait Policy { fn user_name_for_host(&self, host_name: &'static str) -> String { @@ -29,7 +29,7 @@ pub trait Policy { fn socket_path(&self, user_name: &str, service_name: &str) -> PathBuf { format!("/var/tmp/{}-{}.socket", user_name, service_name).into() } - fn acme_user(&self) -> Cow { + fn acme_user(&self) -> Cow<'_, str> { "acme".into() } } @@ -38,22 +38,20 @@ pub struct DefaultPolicy; impl Policy for DefaultPolicy {} -pub struct SymbolFactory<'a, C: 'a + CommandRunner, R: 'a + SymbolRunner, P: 'a + Policy> { +pub struct SymbolFactory<'a, C: CommandRunner, P: Policy> { command_runner: &'a C, acme_factory: AcmeFactory<'a, Cow<'a, str>, PathBuf, &'a str, C>, - symbol_runner: &'a R, policy: &'a P, } -impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFactory<'b, C, R, P> { - pub fn new(command_runner: &'b C, symbol_runner: &'b R, policy: &'b P, cert: &'b str) -> Self { +impl<'b, C: 'b + CommandRunner, P: 'b + Policy> SymbolFactory<'b, C, P> { + pub fn new(command_runner: &'b C, policy: &'b P, cert: &'b str) -> Self { let acme_user = policy.acme_user(); let acme_home = policy.home_for_user(&acme_user); let acme_factory = AcmeFactory::new(acme_user, acme_home, cert, command_runner); SymbolFactory { command_runner, acme_factory, - symbol_runner, policy, } } @@ -289,7 +287,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin ), StoredDirectory::new( string_target, - data.clone(), + data, StorageDirection::Load, self.command_runner, ), @@ -395,7 +393,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin let socket_path = self.policy.socket_path(&user_name, service_name); self.get_nginx_acme_server( host_name, - NginxServer::new_proxy(host_name, socket_path, root_dir, self.command_runner), + NginxServer::new_proxy(host_name, &socket_path, root_dir, self.command_runner), ) } diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index 27da3b6..b837061 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -27,7 +27,7 @@ impl<'a, C: CommandRunner, T: AsRef> GitCheckout<'a, C, T> { } } -impl<'a, C: CommandRunner, T: AsRef> fmt::Display for GitCheckout<'a, C, T> { +impl> fmt::Display for GitCheckout<'_, C, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -39,7 +39,7 @@ impl<'a, C: CommandRunner, T: AsRef> fmt::Display for GitCheckout<'a, C, T } } -impl<'a, C: CommandRunner, T: AsRef> GitCheckout<'a, C, T> { +impl> GitCheckout<'_, C, T> { fn _run_in_target_repo>(&self, args: &[S]) -> Result, Box> { let mut new_args = vec![OsStr::new("-C"), self.target.as_ref().as_ref()]; new_args.extend(args.iter().map(AsRef::as_ref)); @@ -47,7 +47,7 @@ impl<'a, C: CommandRunner, T: AsRef> GitCheckout<'a, C, T> { } } -impl<'a, C: CommandRunner, T: AsRef> Symbol for GitCheckout<'a, C, T> { +impl> Symbol for GitCheckout<'_, C, T> { fn target_reached(&self) -> Result> { if let Err(e) = metadata(self.target.as_ref()) { return if e.kind() == io::ErrorKind::NotFound { diff --git a/src/symbols/git/submodules.rs b/src/symbols/git/submodules.rs index bc00db1..83255d1 100644 --- a/src/symbols/git/submodules.rs +++ b/src/symbols/git/submodules.rs @@ -20,13 +20,13 @@ impl<'a, P: AsRef, C: CommandRunner> GitSubmodules<'a, P, C> { } } -impl<'a, P: AsRef, C: CommandRunner> fmt::Display for GitSubmodules<'a, P, C> { +impl, C: CommandRunner> fmt::Display for GitSubmodules<'_, P, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Submodules for {}", self.target.as_ref().display()) } } -impl<'a, P: AsRef, C: CommandRunner> GitSubmodules<'a, P, C> { +impl, C: CommandRunner> GitSubmodules<'_, P, C> { fn _run_in_target_repo(&self, args: &[&OsStr]) -> Result, Box> { let mut new_args: Vec<&OsStr> = vec![]; new_args.extend_from_slice(args!["-C", self.target.as_ref()]); @@ -35,7 +35,7 @@ impl<'a, P: AsRef, C: CommandRunner> GitSubmodules<'a, P, C> { } } -impl<'a, P: AsRef, C: CommandRunner> Symbol for GitSubmodules<'a, P, C> { +impl, C: CommandRunner> Symbol for GitSubmodules<'_, P, C> { fn target_reached(&self) -> Result> { if !self.target.as_ref().exists() { return Ok(false); diff --git a/src/symbols/list.rs b/src/symbols/list.rs index 37d291b..5925971 100644 --- a/src/symbols/list.rs +++ b/src/symbols/list.rs @@ -14,7 +14,7 @@ impl<'a> List<'a> { } } -impl<'a> Symbol for List<'a> { +impl Symbol for List<'_> { fn target_reached(&self) -> Result> { for symbol in &self.symbols { if !symbol.target_reached()? { @@ -99,7 +99,7 @@ impl<'a> SymbolListAction<'a> { } } -impl<'a> Action for SymbolListAction<'a> { +impl Action for SymbolListAction<'_> { fn run(&self) -> Result<(), Box> { for symbol in self.symbols { symbol.as_action(self.runner).run()?; @@ -118,7 +118,7 @@ impl<'a> ListAction<'a> { } } -impl<'a> Action for ListAction<'a> { +impl Action for ListAction<'_> { fn run(&self) -> Result<(), Box> { for action in &self.actions { action.run()?; @@ -127,7 +127,7 @@ impl<'a> Action for ListAction<'a> { } } -impl<'a> fmt::Display for List<'a> { +impl fmt::Display for List<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "List [ ")?; for symbol in &self.symbols { diff --git a/src/symbols/mariadb/database.rs b/src/symbols/mariadb/database.rs index ec7da66..2d44165 100644 --- a/src/symbols/mariadb/database.rs +++ b/src/symbols/mariadb/database.rs @@ -28,15 +28,15 @@ impl<'a, D: AsRef, S: AsRef, C: CommandRunner> MariaDBDatabase<'a, D, } } -impl<'a, D: AsRef, S: AsRef, C: CommandRunner> fmt::Display - for MariaDBDatabase<'a, D, S, C> +impl, S: AsRef, C: CommandRunner> fmt::Display + for MariaDBDatabase<'_, D, S, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "MariaDB Database {}", self.db_name.as_ref()) } } -impl<'a, D: AsRef, S: AsRef, C: CommandRunner> Symbol for MariaDBDatabase<'a, D, S, C> { +impl, S: AsRef, C: CommandRunner> Symbol for MariaDBDatabase<'_, D, S, C> { fn target_reached(&self) -> Result> { Ok( self diff --git a/src/symbols/mariadb/database_dump.rs b/src/symbols/mariadb/database_dump.rs index 8d0dd2f..355ad1e 100644 --- a/src/symbols/mariadb/database_dump.rs +++ b/src/symbols/mariadb/database_dump.rs @@ -29,13 +29,13 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> } } -impl<'a, N: AsRef, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'a, N, C, S> { +impl, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'_, N, C, S> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Dump MariaDB Database {}", self.db_name.as_ref()) } } -impl<'a, N: AsRef, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { +impl, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'_, N, C, S> { fn target_reached(&self) -> Result> { let dump_date = self.storage.recent_date()?; let modified_date = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref()))?; diff --git a/src/symbols/mariadb/user.rs b/src/symbols/mariadb/user.rs index ee0df12..0037633 100644 --- a/src/symbols/mariadb/user.rs +++ b/src/symbols/mariadb/user.rs @@ -26,13 +26,13 @@ impl<'a, U: AsRef, C: CommandRunner> MariaDBUser<'a, U, C> { } } -impl<'a, U: AsRef, C: CommandRunner> fmt::Display for MariaDBUser<'a, U, C> { +impl, C: CommandRunner> fmt::Display for MariaDBUser<'_, U, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "MariaDB User {}", self.user_name.as_ref()) } } -impl<'a, U: AsRef, C: CommandRunner> Symbol for MariaDBUser<'a, U, C> { +impl, C: CommandRunner> Symbol for MariaDBUser<'_, U, C> { fn target_reached(&self) -> Result> { Ok( self diff --git a/src/symbols/mod.rs b/src/symbols/mod.rs index 57f061b..8c3150f 100644 --- a/src/symbols/mod.rs +++ b/src/symbols/mod.rs @@ -44,7 +44,7 @@ impl<'a, S: Symbol> SymbolAction<'a, S> { } } -impl<'a, S: Symbol> Action for SymbolAction<'a, S> { +impl Action for SymbolAction<'_, S> { fn run(&self) -> Result<(), Box> { self.runner.run_symbol(self.symbol) } diff --git a/src/symbols/nginx/server.rs b/src/symbols/nginx/server.rs index 5d37cb1..45c441f 100644 --- a/src/symbols/nginx/server.rs +++ b/src/symbols/nginx/server.rs @@ -16,7 +16,7 @@ pub enum NginxServerError { impl From for NginxServerError { fn from(err: io::Error) -> Self { - NginxServerError::ExecError(err) + Self::ExecError(err) } } @@ -29,7 +29,7 @@ impl Error for NginxServerError { } fn cause(&self) -> Option<&dyn Error> { match self { - NginxServerError::ExecError(ref e) => Some(e), + Self::ExecError(ref e) => Some(e), _ => None, } } @@ -108,7 +108,7 @@ where pub struct LocalTcpSocket(usize); impl LocalTcpSocket { - pub fn new(x: usize) -> Self { + pub const fn new(x: usize) -> Self { Self(x) } } @@ -130,12 +130,12 @@ impl<'a, C: CommandRunner> NginxServer<'a, C, String, PathBuf> { target ), ); - NginxServer::new(domain, content, command_runner) + Self::new(domain, content, command_runner) } pub fn new_proxy>( domain: &'a str, - socket_path: S, + socket_path: &'_ S, static_path: STATIC, command_runner: &'a C, ) -> Self { @@ -163,7 +163,7 @@ location @proxy {{ proxy_content ), ); - NginxServer::new(domain, content, command_runner) + Self::new(domain, content, command_runner) } pub fn new_php, STATIC: AsRef>( @@ -177,7 +177,7 @@ location @proxy {{ domain, &(php_server_config_snippet(socket_path, static_path) + additional_config), ); - NginxServer::new(domain, content, command_runner) + Self::new(domain, content, command_runner) } pub fn new_static>( @@ -195,7 +195,7 @@ location @proxy {{ static_path.as_ref().to_str().unwrap() ), ); - NginxServer::new(domain, content, command_runner) + Self::new(domain, content, command_runner) } pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self { @@ -207,7 +207,7 @@ location @proxy {{ } } -impl<'a, C: CommandRunner, T: AsRef, P: AsRef> Symbol for NginxServer<'a, C, T, P> { +impl, P: AsRef> Symbol for NginxServer<'_, C, T, P> { fn target_reached(&self) -> Result> { if !self.file.target_reached()? { return Ok(false); @@ -239,9 +239,7 @@ impl<'a, C: CommandRunner, T: AsRef, P: AsRef> Symbol for NginxServer } } -impl<'a, C: CommandRunner, T: AsRef, P: AsRef> fmt::Display - for NginxServer<'a, C, T, P> -{ +impl, P: AsRef> fmt::Display for NginxServer<'_, C, T, P> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "Nginx server config") } diff --git a/src/symbols/npm.rs b/src/symbols/npm.rs index 6df5a02..e9d79ed 100644 --- a/src/symbols/npm.rs +++ b/src/symbols/npm.rs @@ -19,7 +19,7 @@ impl<'a, T: AsRef, C: CommandRunner> NpmInstall<'a, T, C> { } } -impl<'a, T: AsRef, C: CommandRunner> fmt::Display for NpmInstall<'a, T, C> { +impl, C: CommandRunner> fmt::Display for NpmInstall<'_, T, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -29,7 +29,7 @@ impl<'a, T: AsRef, C: CommandRunner> fmt::Display for NpmInstall<'a, T, C> } } -impl<'a, T: AsRef, C: CommandRunner> Symbol for NpmInstall<'a, T, C> { +impl, C: CommandRunner> Symbol for NpmInstall<'_, T, C> { fn target_reached(&self) -> Result> { if !self.target.as_ref().exists() { return Ok(false); diff --git a/src/symbols/owner.rs b/src/symbols/owner.rs index 0b2e529..eed6b92 100644 --- a/src/symbols/owner.rs +++ b/src/symbols/owner.rs @@ -27,7 +27,7 @@ impl<'a, C: CommandRunner, D: AsRef, U: AsRef> Owner<'a, C, D, U> { } } -impl<'a, C: CommandRunner, D: AsRef, U: AsRef> Symbol for Owner<'a, C, D, U> { +impl, U: AsRef> Symbol for Owner<'_, C, D, U> { fn target_reached(&self) -> Result> { if !Path::new(self.path.as_ref()).exists() { return Ok(false); @@ -60,7 +60,7 @@ impl<'a, C: CommandRunner, D: AsRef, U: AsRef> Symbol for Owner<'a, C } } -impl<'a, C: CommandRunner, D: AsRef, U: AsRef> fmt::Display for Owner<'a, C, D, U> { +impl, U: AsRef> fmt::Display for Owner<'_, C, D, U> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!( f, diff --git a/src/symbols/postgresql/database.rs b/src/symbols/postgresql/database.rs index d41a43b..1ef3728 100644 --- a/src/symbols/postgresql/database.rs +++ b/src/symbols/postgresql/database.rs @@ -28,17 +28,15 @@ impl<'a, N: AsRef, S: AsRef, C: CommandRunner> PostgreSQLDatabase<'a, } } -impl<'a, N: AsRef, S: AsRef, C: CommandRunner> fmt::Display - for PostgreSQLDatabase<'a, N, S, C> +impl, S: AsRef, C: CommandRunner> fmt::Display + for PostgreSQLDatabase<'_, N, S, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "PostgreSQL Database {}", self.name.as_ref()) } } -impl<'a, N: AsRef, S: AsRef, C: CommandRunner> Symbol - for PostgreSQLDatabase<'a, N, S, C> -{ +impl, S: AsRef, C: CommandRunner> Symbol for PostgreSQLDatabase<'_, N, S, C> { fn target_reached(&self) -> Result> { Ok( self diff --git a/src/symbols/postgresql/database_dump.rs b/src/symbols/postgresql/database_dump.rs deleted file mode 100644 index 8d0dd2f..0000000 --- a/src/symbols/postgresql/database_dump.rs +++ /dev/null @@ -1,75 +0,0 @@ -use std::error::Error; -use std::fmt; -use std::str::FromStr; - -use crate::command_runner::CommandRunner; -use crate::storage::Storage; -use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; - -pub struct DatabaseDump<'a, N: AsRef, C: CommandRunner, S: Storage> { - db_name: N, - storage: S, - command_runner: &'a C, -} - -impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> { - pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self { - DatabaseDump { - db_name, - storage, - command_runner, - } - } - - fn run_sql(&self, sql: &str) -> Result> { - let b = self - .command_runner - .get_output("mariadb", args!["--skip-column-names", "-B", "-e", sql])?; - Ok(String::from_utf8(b)?) - } -} - -impl<'a, N: AsRef, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'a, N, C, S> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Dump MariaDB Database {}", self.db_name.as_ref()) - } -} - -impl<'a, N: AsRef, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { - fn target_reached(&self) -> Result> { - let dump_date = self.storage.recent_date()?; - let modified_date = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref()))?; - if modified_date.trim_end() == "NULL" { - return Ok(false); - } - Ok(u64::from_str(modified_date.trim_end())? <= dump_date) - } - - fn execute(&self) -> Result<(), Box> { - self.command_runner.run_successfully( - "sh", - args![ - "-c", - format!( - "mysqldump '{}' > {}", - self.db_name.as_ref(), - self.storage.write_filename() - ), - ], - ) - } - - fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { - Box::new(SymbolAction::new(runner, self)) - } - - fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box - where - Self: 'b, - { - Box::new(OwnedSymbolAction::new(runner, *self)) - } -} - -#[cfg(test)] -mod test {} diff --git a/src/symbols/postgresql/mod.rs b/src/symbols/postgresql/mod.rs index 4a2a535..5e80d91 100644 --- a/src/symbols/postgresql/mod.rs +++ b/src/symbols/postgresql/mod.rs @@ -1,5 +1,3 @@ mod database; -mod database_dump; pub use self::database::PostgreSQLDatabase; -//pub use self::database_dump::PostgreSQLDump; diff --git a/src/symbols/stored_directory.rs b/src/symbols/stored_directory.rs index e31ba04..827e807 100644 --- a/src/symbols/stored_directory.rs +++ b/src/symbols/stored_directory.rs @@ -34,9 +34,7 @@ impl<'a, P: AsRef, S: Storage, C: CommandRunner> StoredDirectory<'a, P, S, } } -impl<'a, P: AsRef, S: Storage, C: CommandRunner> fmt::Display - for StoredDirectory<'a, P, S, C> -{ +impl, S: Storage, C: CommandRunner> fmt::Display for StoredDirectory<'_, P, S, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -47,7 +45,7 @@ impl<'a, P: AsRef, S: Storage, C: CommandRunner> fmt::Display } } -impl<'a, P: AsRef, S: Storage, C: CommandRunner> Symbol for StoredDirectory<'a, P, S, C> { +impl, S: Storage, C: CommandRunner> Symbol for StoredDirectory<'_, P, S, C> { fn target_reached(&self) -> Result> { let metadata = fs::metadata(self.path.as_ref()); // Check if dir exists diff --git a/src/symbols/systemd/reload.rs b/src/symbols/systemd/reload.rs index 7681ddd..354385c 100644 --- a/src/symbols/systemd/reload.rs +++ b/src/symbols/systemd/reload.rs @@ -18,7 +18,7 @@ impl<'a, C: CommandRunner> ReloadService<'a, C> { } } -impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> { +impl Symbol for ReloadService<'_, C> { fn target_reached(&self) -> Result> { Ok(true) } @@ -41,7 +41,7 @@ impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> { } } -impl<'a, C: CommandRunner> fmt::Display for ReloadService<'a, C> { +impl fmt::Display for ReloadService<'_, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "Reload service {}", self.service) } diff --git a/src/symbols/systemd/user_service.rs b/src/symbols/systemd/user_service.rs index b3e9359..9d9eff0 100644 --- a/src/symbols/systemd/user_service.rs +++ b/src/symbols/systemd/user_service.rs @@ -29,14 +29,14 @@ impl From for UserServiceError { impl Error for UserServiceError { fn description(&self) -> &str { match self { - UserServiceError::ExecError(ref e) => e.description(), - UserServiceError::GenericError => "Generic error", - UserServiceError::ActivationFailed(_) => "Activation of service failed", + Self::ExecError(ref e) => e.description(), + Self::GenericError => "Generic error", + Self::ActivationFailed(_) => "Activation of service failed", } } fn cause(&self) -> Option<&dyn Error> { match self { - UserServiceError::ExecError(ref e) => Some(e), + Self::ExecError(ref e) => Some(e), _ => None, } } @@ -126,9 +126,7 @@ WantedBy=default.target } } -impl<'a, S: AsRef, U: AsRef, C: AsRef, R: CommandRunner> - UserService<'a, S, U, C, R> -{ +impl, U: AsRef, C: AsRef, R: CommandRunner> UserService<'_, S, U, C, R> { fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result> { let mut tries = 5; loop { @@ -176,8 +174,8 @@ impl<'a, S: AsRef, U: AsRef, C: AsRef, R: CommandRunner> } } -impl<'a, S: AsRef, U: AsRef, C: AsRef, R: CommandRunner> Symbol - for UserService<'a, S, U, C, R> +impl, U: AsRef, C: AsRef, R: CommandRunner> Symbol + for UserService<'_, S, U, C, R> { fn target_reached(&self) -> Result> { if !(self.config.target_reached()?) { @@ -226,8 +224,8 @@ impl<'a, S: AsRef, U: AsRef, C: AsRef, R: CommandRunner> Symbol } } -impl<'a, S: AsRef, U: AsRef, C: AsRef, R: CommandRunner> fmt::Display - for UserService<'a, S, U, C, R> +impl, U: AsRef, C: AsRef, R: CommandRunner> fmt::Display + for UserService<'_, S, U, C, R> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "Systemd user service unit for {}", self.service_name) diff --git a/src/symbols/systemd/user_session.rs b/src/symbols/systemd/user_session.rs index e2dafc6..496d08e 100644 --- a/src/symbols/systemd/user_session.rs +++ b/src/symbols/systemd/user_session.rs @@ -14,13 +14,13 @@ pub enum SystemdUserSessionError { impl Error for SystemdUserSessionError { fn description(&self) -> &str { match self { - SystemdUserSessionError::ExecError(ref e) => e.description(), - SystemdUserSessionError::GenericError => "Generic error", + Self::ExecError(ref e) => e.description(), + Self::GenericError => "Generic error", } } fn cause(&self) -> Option<&dyn Error> { match self { - SystemdUserSessionError::ExecError(ref e) => Some(e), + Self::ExecError(ref e) => Some(e), _ => None, } } @@ -46,7 +46,7 @@ impl<'a, U: AsRef, C: CommandRunner> SystemdUserSession<'a, U, C> { } } -impl<'a, U: AsRef, C: CommandRunner> Symbol for SystemdUserSession<'a, U, C> { +impl, C: CommandRunner> Symbol for SystemdUserSession<'_, U, C> { fn target_reached(&self) -> Result> { let mut path = PathBuf::from("/var/lib/systemd/linger"); path.push(self.user_name.as_ref()); @@ -72,7 +72,7 @@ impl<'a, U: AsRef, C: CommandRunner> Symbol for SystemdUserSession<'a, U, C } } -impl<'a, U: AsRef, C: CommandRunner> fmt::Display for SystemdUserSession<'a, U, C> { +impl, C: CommandRunner> fmt::Display for SystemdUserSession<'_, U, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "Systemd user session for {}", self.user_name.as_ref()) } diff --git a/src/symbols/tls/csr.rs b/src/symbols/tls/csr.rs index 5e9e383..3b81566 100644 --- a/src/symbols/tls/csr.rs +++ b/src/symbols/tls/csr.rs @@ -30,13 +30,13 @@ impl<'a, C: CommandRunner> TlsCsr<'a, C> { } } -impl<'a, C: CommandRunner> fmt::Display for TlsCsr<'a, C> { +impl fmt::Display for TlsCsr<'_, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "TlsCsr {}", self.domain) } } -impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> { +impl Symbol for TlsCsr<'_, C> { fn target_reached(&self) -> Result> { if !self.get_csr_path().exists() { return Ok(false); diff --git a/src/symbols/tls/key.rs b/src/symbols/tls/key.rs index 9a9fad1..e819111 100644 --- a/src/symbols/tls/key.rs +++ b/src/symbols/tls/key.rs @@ -31,13 +31,13 @@ impl<'a, C: CommandRunner> TlsKey<'a, C> { } } -impl<'a, C: CommandRunner> fmt::Display for TlsKey<'a, C> { +impl fmt::Display for TlsKey<'_, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "TlsKey {}", self.domain) } } -impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> { +impl Symbol for TlsKey<'_, C> { fn target_reached(&self) -> Result> { if !self.get_path().exists() { return Ok(false); @@ -54,7 +54,7 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> { "-text".as_ref(), ], )?; - Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) + Ok(output.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) } fn execute(&self) -> Result<(), Box> { diff --git a/src/symbols/tls/self_signed_cert.rs b/src/symbols/tls/self_signed_cert.rs index 7724330..71c0c4a 100644 --- a/src/symbols/tls/self_signed_cert.rs +++ b/src/symbols/tls/self_signed_cert.rs @@ -28,7 +28,7 @@ impl<'a, D: AsRef, C: CommandRunner> SelfSignedTlsCert<'a, D, C> { } } -impl<'a, D: AsRef, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a, D, C> { +impl, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'_, D, C> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "SelfSignedTlsCert {}", self.domain.as_ref()) } @@ -36,7 +36,7 @@ impl<'a, D: AsRef, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a, const DAYS_IN_SECONDS: u32 = 24 * 60 * 60; -impl<'a, D: AsRef, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, D, C> { +impl, C: CommandRunner> Symbol for SelfSignedTlsCert<'_, D, C> { fn target_reached(&self) -> Result> { if !self.get_cert_path().exists() { return Ok(false); diff --git a/src/symbols/user.rs b/src/symbols/user.rs index 3448a74..e3ca95d 100644 --- a/src/symbols/user.rs +++ b/src/symbols/user.rs @@ -16,14 +16,14 @@ pub enum UserAdderError { impl Error for UserAdderError { fn description(&self) -> &str { match self { - UserAdderError::AlreadyExists => "User already exists", - UserAdderError::UnknownError => "Unknown error", - UserAdderError::ImplError(_) => "User adding error", + Self::AlreadyExists => "User already exists", + Self::UnknownError => "Unknown error", + Self::ImplError(_) => "User adding error", } } - fn cause(&self) -> Option<&dyn Error> { + fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - UserAdderError::ImplError(ref e) => Some(e.as_ref()), + Self::ImplError(ref e) => Some(e.as_ref()), _ => None, } } @@ -31,7 +31,7 @@ impl Error for UserAdderError { impl fmt::Display for UserAdderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.cause() { + match self.source() { Some(e) => write!(f, "{} (cause: {})", self.description(), e), None => write!(f, "{}", self.description()), } @@ -50,10 +50,10 @@ pub enum UserError { impl Error for UserError { fn description(&self) -> &str { match self { - UserError::GenericError => "Could not find out if user exists", + Self::GenericError => "Could not find out if user exists", } } - fn cause(&self) -> Option<&dyn Error> { + fn source(&self) -> Option<&(dyn Error + 'static)> { match self { _ => None, } @@ -62,7 +62,7 @@ impl Error for UserError { impl fmt::Display for UserError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.cause() { + match self.source() { Some(e) => write!(f, "{} (cause: {})", self.description(), e), None => write!(f, "{}", self.description()), } @@ -136,7 +136,7 @@ impl<'a, C: CommandRunner> SystemUserAdder<'a, C> { } } -impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> { +impl UserAdder for SystemUserAdder<'_, C> { fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> { let output = self.command_runner.run_with_args( "adduser", @@ -152,11 +152,7 @@ impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> { println!("{:?}", output); Err(UserAdderError::AlreadyExists) } - Some(_) => { - println!("{:?}", output); - Err(UserAdderError::UnknownError) - } - None => { + _ => { println!("{:?}", output); Err(UserAdderError::UnknownError) } diff --git a/src/symbols/wordpress/plugin.rs b/src/symbols/wordpress/plugin.rs index 7a17deb..1bdb1c9 100644 --- a/src/symbols/wordpress/plugin.rs +++ b/src/symbols/wordpress/plugin.rs @@ -34,7 +34,7 @@ impl<'a, P: AsRef, N: AsRef, R: CommandRunner> WordpressPlugin<'a, P, } } -impl<'a, P: AsRef, N: AsRef, R: CommandRunner> Symbol for WordpressPlugin<'a, P, N, R> { +impl, N: AsRef, R: CommandRunner> Symbol for WordpressPlugin<'_, P, N, R> { fn target_reached(&self) -> Result> { let base_path = self.get_path(); if !base_path.exists() { @@ -119,8 +119,8 @@ impl<'a, P: AsRef, N: AsRef, R: CommandRunner> Symbol for WordpressPl } } -impl<'a, P: AsRef, N: AsRef, R: CommandRunner> fmt::Display - for WordpressPlugin<'a, P, N, R> +impl, N: AsRef, R: CommandRunner> fmt::Display + for WordpressPlugin<'_, P, N, R> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "WordpressPlugin {}", self.name.as_ref()) diff --git a/src/symbols/wordpress/translation.rs b/src/symbols/wordpress/translation.rs index 9876be7..ea1aea2 100644 --- a/src/symbols/wordpress/translation.rs +++ b/src/symbols/wordpress/translation.rs @@ -33,7 +33,7 @@ impl<'a, C: AsRef, R: CommandRunner> WordpressTranslation<'a, C, PathBuf, R } } -impl<'a, C: AsRef, D: AsRef, R: CommandRunner> WordpressTranslation<'a, C, D, R> { +impl, D: AsRef, R: CommandRunner> WordpressTranslation<'_, C, D, R> { fn get_pairs(&self) -> Vec<(String, PathBuf)> { let version_x = self .version @@ -47,15 +47,13 @@ impl<'a, C: AsRef, D: AsRef, R: CommandRunner> WordpressTranslation<' locale.to_lowercase().replace('_', "-") }; let mut res = vec![]; - for &(in_slug, out_slug) in [ + for &(in_slug, out_slug) in &[ ("", ""), ("cc/", "continents-cities-"), ("admin/", "admin-"), ("admin/network/", "admin-network-"), - ] - .iter() - { - for format in ["po", "mo"].iter() { + ] { + for format in &["po", "mo"] { res.push(( format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format), [self.path.as_ref(), format!("{}{}.{}", out_slug, self.locale.as_ref(), format).as_ref()].iter().collect() @@ -66,9 +64,7 @@ impl<'a, C: AsRef, D: AsRef, R: CommandRunner> WordpressTranslation<' } } -impl<'a, C: AsRef, D: AsRef, R: CommandRunner> Symbol - for WordpressTranslation<'a, C, D, R> -{ +impl, D: AsRef, R: CommandRunner> Symbol for WordpressTranslation<'_, C, D, R> { fn target_reached(&self) -> Result> { let mut newest = String::new(); let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap(); @@ -136,8 +132,8 @@ impl<'a, C: AsRef, D: AsRef, R: CommandRunner> Symbol } } -impl<'a, C: AsRef, D: AsRef, R: CommandRunner> fmt::Display - for WordpressTranslation<'a, C, D, R> +impl, D: AsRef, R: CommandRunner> fmt::Display + for WordpressTranslation<'_, C, D, R> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "WordpressTranslation {}", self.path.as_ref().display())