Browse Source

Lint

master
Adrian Heine 5 years ago
parent
commit
e060ce5a68
  1. 8
      src/command_runner.rs
  2. 14
      src/factory.rs
  3. 28
      src/lib.rs
  4. 2
      src/loggers.rs
  5. 23
      src/schema.rs
  6. 2
      src/storage.rs
  7. 6
      src/symbols/acme/account_key.rs
  8. 8
      src/symbols/acme/cert.rs
  9. 6
      src/symbols/acme/chain.rs
  10. 2
      src/symbols/acme/mod.rs
  11. 4
      src/symbols/cron.rs
  12. 16
      src/symbols/factory.rs
  13. 6
      src/symbols/git/checkout.rs
  14. 6
      src/symbols/git/submodules.rs
  15. 8
      src/symbols/list.rs
  16. 6
      src/symbols/mariadb/database.rs
  17. 4
      src/symbols/mariadb/database_dump.rs
  18. 4
      src/symbols/mariadb/user.rs
  19. 2
      src/symbols/mod.rs
  20. 22
      src/symbols/nginx/server.rs
  21. 4
      src/symbols/npm.rs
  22. 4
      src/symbols/owner.rs
  23. 8
      src/symbols/postgresql/database.rs
  24. 75
      src/symbols/postgresql/database_dump.rs
  25. 2
      src/symbols/postgresql/mod.rs
  26. 6
      src/symbols/stored_directory.rs
  27. 4
      src/symbols/systemd/reload.rs
  28. 20
      src/symbols/systemd/user_service.rs
  29. 10
      src/symbols/systemd/user_session.rs
  30. 4
      src/symbols/tls/csr.rs
  31. 6
      src/symbols/tls/key.rs
  32. 4
      src/symbols/tls/self_signed_cert.rs
  33. 26
      src/symbols/user.rs
  34. 6
      src/symbols/wordpress/plugin.rs
  35. 18
      src/symbols/wordpress/translation.rs

8
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) { fn drop(&mut self) {
match self.old_value { match self.old_value {
Some(ref val) => env::set_var(self.name, val), Some(ref val) => env::set_var(self.name, val),
@ -115,7 +115,7 @@ impl<'a> Drop for TempSetEnv<'a> {
} }
} }
impl<'a, U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'a, U, C> {
impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> {
fn run_with_args_and_stdin( fn run_with_args_and_stdin(
&self, &self,
program: &str, program: &str,
@ -125,8 +125,8 @@ impl<'a, U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<
let uid = get_user_by_name(self.user_name.as_ref()) let uid = get_user_by_name(self.user_name.as_ref())
.expect("User does not exist") .expect("User does not exist")
.uid(); .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); //println!("{} {:?}", program, args);
let mut child = Command::new(program) let mut child = Command::new(program)
.args(args) .args(args)

14
src/factory.rs

@ -21,7 +21,7 @@ pub struct Factory {}
impl Factory { impl Factory {
pub fn new() -> Self { pub fn new() -> Self {
Default::default()
Self::default()
} }
pub fn get_repo<'a, CR: CommandRunner>( pub fn get_repo<'a, CR: CommandRunner>(
@ -87,15 +87,15 @@ impl<'a, C: CommandRunner> SymbolRepository<'a>
matches[1].to_string(), matches[1].to_string(),
self.command_runner, self.command_runner,
)), )),
])) as Box<dyn Symbol>
]))
} else if let Some(matches) = self.home.captures(value) { } else if let Some(matches) = self.home.captures(value) {
Box::new(User::new( Box::new(User::new(
matches[1].to_string().into(), matches[1].to_string().into(),
self.command_runner, self.command_runner,
&self.user_adder, &self.user_adder,
)) as Box<dyn Symbol>
))
} else { } else {
Box::new(Dir::new(value.to_string())) as Box<dyn Symbol>
Box::new(Dir::new(value.to_string()))
}) })
} }
"file" => { "file" => {
@ -104,17 +104,17 @@ impl<'a, C: CommandRunner> SymbolRepository<'a>
Some(Box::new(TlsCsr::new( Some(Box::new(TlsCsr::new(
matches[1].to_string().into(), matches[1].to_string().into(),
self.command_runner, self.command_runner,
)) as Box<dyn Symbol>)
)))
} else if let Some(matches) = self.private_key.captures(value) { } else if let Some(matches) = self.private_key.captures(value) {
Some(Box::new(TlsKey::new( Some(Box::new(TlsKey::new(
matches[1].to_string().into(), matches[1].to_string().into(),
self.command_runner, self.command_runner,
)) as Box<dyn Symbol>)
)))
} else if let Some(matches) = self.systemd_linger.captures(value) { } else if let Some(matches) = self.systemd_linger.captures(value) {
Some(Box::new(SystemdUserSession::new( Some(Box::new(SystemdUserSession::new(
matches[1].to_string(), matches[1].to_string(),
self.command_runner, self.command_runner,
)) as Box<dyn Symbol>)
)))
} else { } else {
None None
} }

28
src/lib.rs

@ -1,23 +1,29 @@
// rustfmt
#![deny( #![deny(
macro_use_extern_crate,
meta_variable_misuse,
non_ascii_idents,
trivial_numeric_casts, trivial_numeric_casts,
unused,
unreachable_pub,
unsafe_code, unsafe_code,
unstable_features, unstable_features,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
variant_size_differences, 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,
#![allow(
single_use_lifetimes,
trivial_casts,
clippy::module_name_repetitions,
clippy::cargo_common_metadata,
rustdoc,
missing_docs,
missing_copy_implementations, missing_copy_implementations,
missing_debug_implementations missing_debug_implementations
)] )]
*/
#![allow(box_pointers)]
#[macro_use] #[macro_use]
mod for_each_tuple; mod for_each_tuple;

2
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 debug(&mut self, _str: &str) {}
fn write(&mut self, str: &str) { fn write(&mut self, str: &str) {
self.logger.write(str) self.logger.write(str)

23
src/schema.rs

@ -15,14 +15,14 @@ pub enum SymbolRunError {
impl Error for SymbolRunError { impl Error for SymbolRunError {
fn description(&self) -> &str { fn description(&self) -> &str {
match self { 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> { fn cause(&self) -> Option<&dyn Error> {
match self { 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 { impl fmt::Display for SymbolRunError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { 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(); let mut logger = self.1.borrow_mut();
logger.debug(format!("Running symbol {}", symbol).as_str()); logger.debug(format!("Running symbol {}", symbol).as_str());
let res = self.0.run_symbol(symbol); 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 res
} }

2
src/storage.rs

@ -13,7 +13,7 @@ pub trait Storage {
pub struct SimpleStorage(String, String); pub struct SimpleStorage(String, String);
impl SimpleStorage { impl SimpleStorage {
pub fn new(base: String, filename: String) -> Self {
pub const fn new(base: String, filename: String) -> Self {
Self(base, filename) Self(base, filename)
} }

6
src/symbols/acme/account_key.rs

@ -24,13 +24,13 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> AcmeAccountKey<'a, P, C> {
} }
} }
impl<'a, P: AsRef<Path>, C: CommandRunner> fmt::Display for AcmeAccountKey<'a, P, C> {
impl<P: AsRef<Path>, C: CommandRunner> fmt::Display for AcmeAccountKey<'_, P, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "AcmeAccountKey {}", self.path.as_ref().display()) write!(f, "AcmeAccountKey {}", self.path.as_ref().display())
} }
} }
impl<'a, P: AsRef<Path>, C: CommandRunner> Symbol for AcmeAccountKey<'a, P, C> {
impl<P: AsRef<Path>, C: CommandRunner> Symbol for AcmeAccountKey<'_, P, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.path.as_ref().exists() { if !self.path.as_ref().exists() {
return Ok(false); return Ok(false);
@ -46,7 +46,7 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> Symbol for AcmeAccountKey<'a, P, C> {
"-text", "-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<dyn Error>> { fn execute(&self) -> Result<(), Box<dyn Error>> {

8
src/symbols/acme/cert.rs

@ -51,8 +51,8 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: As
} }
} }
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>>
fmt::Display for AcmeCert<'a, D, R, C, K, CH>
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>> fmt::Display
for AcmeCert<'_, D, R, C, K, CH>
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "AcmeCert {}", self.domain.as_ref()) write!(f, "AcmeCert {}", self.domain.as_ref())
@ -61,8 +61,8 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: As
const DAYS_IN_SECONDS: u32 = 24 * 60 * 60; const DAYS_IN_SECONDS: u32 = 24 * 60 * 60;
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>> Symbol
for AcmeCert<'a, D, R, C, K, CH>
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>> Symbol
for AcmeCert<'_, D, R, C, K, CH>
{ {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.get_cert_path().exists() { if !self.get_cert_path().exists() {

6
src/symbols/acme/chain.rs

@ -32,9 +32,7 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> AcmeCertChain<'a, D, R
} }
} }
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> fmt::Display
for AcmeCertChain<'a, D, R, C>
{
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> fmt::Display for AcmeCertChain<'_, D, R, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "AcmeCertChain {}", self.domain.as_ref()) write!(f, "AcmeCertChain {}", self.domain.as_ref())
} }
@ -42,7 +40,7 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> fmt::Display
const DAYS_IN_SECONDS: u32 = 24 * 60 * 60; const DAYS_IN_SECONDS: u32 = 24 * 60 * 60;
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> Symbol for AcmeCertChain<'a, D, R, C> {
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> Symbol for AcmeCertChain<'_, D, R, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.get_cert_chain_path().exists() { if !self.get_cert_chain_path().exists() {
return Ok(false); return Ok(false);

2
src/symbols/acme/mod.rs

@ -41,7 +41,7 @@ impl<'a, U: Clone + AsRef<str>, H: AsRef<Path>, C: AsRef<str>, R: CommandRunner>
acme_command_runner, acme_command_runner,
} }
} }
pub fn get_challenges_dir(&'a self) -> Cow<Path> {
pub fn get_challenges_dir(&'a self) -> Cow<'_, Path> {
[self.home_dir.as_ref(), "challenges".as_ref()] [self.home_dir.as_ref(), "challenges".as_ref()]
.iter() .iter()
.collect::<PathBuf>() .collect::<PathBuf>()

4
src/symbols/cron.rs

@ -21,7 +21,7 @@ impl<'r, U: AsRef<str>, R: CommandRunner> Cron<'r, String, U, R> {
} }
} }
impl<'r, C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'r, C, U, R> {
impl<C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'_, C, U, R> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let tab = self let tab = self
.command_runner .command_runner
@ -53,7 +53,7 @@ impl<'r, C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'r, C,
} }
} }
impl<'r, C: AsRef<str>, U: AsRef<str>, R: CommandRunner> fmt::Display for Cron<'r, C, U, R> {
impl<C: AsRef<str>, U: AsRef<str>, R: CommandRunner> fmt::Display for Cron<'_, C, U, R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Cron {}", self.user.as_ref()) write!(f, "Cron {}", self.user.as_ref())
} }

16
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::reload::ReloadService;
use crate::symbols::systemd::user_service::UserService; use crate::symbols::systemd::user_service::UserService;
use crate::symbols::tls::SelfSignedTlsCert; use crate::symbols::tls::SelfSignedTlsCert;
use crate::symbols::{Symbol, SymbolRunner};
use crate::symbols::Symbol;
pub trait Policy { pub trait Policy {
fn user_name_for_host(&self, host_name: &'static str) -> String { 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 { fn socket_path(&self, user_name: &str, service_name: &str) -> PathBuf {
format!("/var/tmp/{}-{}.socket", user_name, service_name).into() format!("/var/tmp/{}-{}.socket", user_name, service_name).into()
} }
fn acme_user(&self) -> Cow<str> {
fn acme_user(&self) -> Cow<'_, str> {
"acme".into() "acme".into()
} }
} }
@ -38,22 +38,20 @@ pub struct DefaultPolicy;
impl Policy for 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, command_runner: &'a C,
acme_factory: AcmeFactory<'a, Cow<'a, str>, PathBuf, &'a str, C>, acme_factory: AcmeFactory<'a, Cow<'a, str>, PathBuf, &'a str, C>,
symbol_runner: &'a R,
policy: &'a P, 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_user = policy.acme_user();
let acme_home = policy.home_for_user(&acme_user); let acme_home = policy.home_for_user(&acme_user);
let acme_factory = AcmeFactory::new(acme_user, acme_home, cert, command_runner); let acme_factory = AcmeFactory::new(acme_user, acme_home, cert, command_runner);
SymbolFactory { SymbolFactory {
command_runner, command_runner,
acme_factory, acme_factory,
symbol_runner,
policy, policy,
} }
} }
@ -289,7 +287,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
), ),
StoredDirectory::new( StoredDirectory::new(
string_target, string_target,
data.clone(),
data,
StorageDirection::Load, StorageDirection::Load,
self.command_runner, 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); let socket_path = self.policy.socket_path(&user_name, service_name);
self.get_nginx_acme_server( self.get_nginx_acme_server(
host_name, 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),
) )
} }

6
src/symbols/git/checkout.rs

@ -27,7 +27,7 @@ impl<'a, C: CommandRunner, T: AsRef<Path>> GitCheckout<'a, C, T> {
} }
} }
impl<'a, C: CommandRunner, T: AsRef<Path>> fmt::Display for GitCheckout<'a, C, T> {
impl<C: CommandRunner, T: AsRef<Path>> fmt::Display for GitCheckout<'_, C, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
@ -39,7 +39,7 @@ impl<'a, C: CommandRunner, T: AsRef<Path>> fmt::Display for GitCheckout<'a, C, T
} }
} }
impl<'a, C: CommandRunner, T: AsRef<Path>> GitCheckout<'a, C, T> {
impl<C: CommandRunner, T: AsRef<Path>> GitCheckout<'_, C, T> {
fn _run_in_target_repo<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<Vec<u8>, Box<dyn Error>> { fn _run_in_target_repo<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<Vec<u8>, Box<dyn Error>> {
let mut new_args = vec![OsStr::new("-C"), self.target.as_ref().as_ref()]; let mut new_args = vec![OsStr::new("-C"), self.target.as_ref().as_ref()];
new_args.extend(args.iter().map(AsRef::as_ref)); new_args.extend(args.iter().map(AsRef::as_ref));
@ -47,7 +47,7 @@ impl<'a, C: CommandRunner, T: AsRef<Path>> GitCheckout<'a, C, T> {
} }
} }
impl<'a, C: CommandRunner, T: AsRef<Path>> Symbol for GitCheckout<'a, C, T> {
impl<C: CommandRunner, T: AsRef<Path>> Symbol for GitCheckout<'_, C, T> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if let Err(e) = metadata(self.target.as_ref()) { if let Err(e) = metadata(self.target.as_ref()) {
return if e.kind() == io::ErrorKind::NotFound { return if e.kind() == io::ErrorKind::NotFound {

6
src/symbols/git/submodules.rs

@ -20,13 +20,13 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> GitSubmodules<'a, P, C> {
} }
} }
impl<'a, P: AsRef<Path>, C: CommandRunner> fmt::Display for GitSubmodules<'a, P, C> {
impl<P: AsRef<Path>, C: CommandRunner> fmt::Display for GitSubmodules<'_, P, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Submodules for {}", self.target.as_ref().display()) write!(f, "Submodules for {}", self.target.as_ref().display())
} }
} }
impl<'a, P: AsRef<Path>, C: CommandRunner> GitSubmodules<'a, P, C> {
impl<P: AsRef<Path>, C: CommandRunner> GitSubmodules<'_, P, C> {
fn _run_in_target_repo(&self, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> { fn _run_in_target_repo(&self, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> {
let mut new_args: Vec<&OsStr> = vec![]; let mut new_args: Vec<&OsStr> = vec![];
new_args.extend_from_slice(args!["-C", self.target.as_ref()]); new_args.extend_from_slice(args!["-C", self.target.as_ref()]);
@ -35,7 +35,7 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> GitSubmodules<'a, P, C> {
} }
} }
impl<'a, P: AsRef<Path>, C: CommandRunner> Symbol for GitSubmodules<'a, P, C> {
impl<P: AsRef<Path>, C: CommandRunner> Symbol for GitSubmodules<'_, P, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.target.as_ref().exists() { if !self.target.as_ref().exists() {
return Ok(false); return Ok(false);

8
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<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
for symbol in &self.symbols { for symbol in &self.symbols {
if !symbol.target_reached()? { 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<dyn Error>> { fn run(&self) -> Result<(), Box<dyn Error>> {
for symbol in self.symbols { for symbol in self.symbols {
symbol.as_action(self.runner).run()?; 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<dyn Error>> { fn run(&self) -> Result<(), Box<dyn Error>> {
for action in &self.actions { for action in &self.actions {
action.run()?; 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> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "List [ ")?; write!(f, "List [ ")?;
for symbol in &self.symbols { for symbol in &self.symbols {

6
src/symbols/mariadb/database.rs

@ -28,15 +28,15 @@ impl<'a, D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> MariaDBDatabase<'a, D,
} }
} }
impl<'a, D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> fmt::Display
for MariaDBDatabase<'a, D, S, C>
impl<D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> fmt::Display
for MariaDBDatabase<'_, D, S, C>
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "MariaDB Database {}", self.db_name.as_ref()) write!(f, "MariaDB Database {}", self.db_name.as_ref())
} }
} }
impl<'a, D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> Symbol for MariaDBDatabase<'a, D, S, C> {
impl<D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> Symbol for MariaDBDatabase<'_, D, S, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok( Ok(
self self

4
src/symbols/mariadb/database_dump.rs

@ -29,13 +29,13 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S>
} }
} }
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'a, N, C, S> {
impl<N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'_, N, C, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Dump MariaDB Database {}", self.db_name.as_ref()) write!(f, "Dump MariaDB Database {}", self.db_name.as_ref())
} }
} }
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> {
impl<N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'_, N, C, S> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let dump_date = self.storage.recent_date()?; 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()))?; 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()))?;

4
src/symbols/mariadb/user.rs

@ -26,13 +26,13 @@ impl<'a, U: AsRef<str>, C: CommandRunner> MariaDBUser<'a, U, C> {
} }
} }
impl<'a, U: AsRef<str>, C: CommandRunner> fmt::Display for MariaDBUser<'a, U, C> {
impl<U: AsRef<str>, C: CommandRunner> fmt::Display for MariaDBUser<'_, U, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "MariaDB User {}", self.user_name.as_ref()) write!(f, "MariaDB User {}", self.user_name.as_ref())
} }
} }
impl<'a, U: AsRef<str>, C: CommandRunner> Symbol for MariaDBUser<'a, U, C> {
impl<U: AsRef<str>, C: CommandRunner> Symbol for MariaDBUser<'_, U, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok( Ok(
self self

2
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<S: Symbol> Action for SymbolAction<'_, S> {
fn run(&self) -> Result<(), Box<dyn Error>> { fn run(&self) -> Result<(), Box<dyn Error>> {
self.runner.run_symbol(self.symbol) self.runner.run_symbol(self.symbol)
} }

22
src/symbols/nginx/server.rs

@ -16,7 +16,7 @@ pub enum NginxServerError<E: Error> {
impl From<io::Error> for NginxServerError<io::Error> { impl From<io::Error> for NginxServerError<io::Error> {
fn from(err: io::Error) -> Self { fn from(err: io::Error) -> Self {
NginxServerError::ExecError(err)
Self::ExecError(err)
} }
} }
@ -29,7 +29,7 @@ impl<E: Error> Error for NginxServerError<E> {
} }
fn cause(&self) -> Option<&dyn Error> { fn cause(&self) -> Option<&dyn Error> {
match self { match self {
NginxServerError::ExecError(ref e) => Some(e),
Self::ExecError(ref e) => Some(e),
_ => None, _ => None,
} }
} }
@ -108,7 +108,7 @@ where
pub struct LocalTcpSocket(usize); pub struct LocalTcpSocket(usize);
impl LocalTcpSocket { impl LocalTcpSocket {
pub fn new(x: usize) -> Self {
pub const fn new(x: usize) -> Self {
Self(x) Self(x)
} }
} }
@ -130,12 +130,12 @@ impl<'a, C: CommandRunner> NginxServer<'a, C, String, PathBuf> {
target target
), ),
); );
NginxServer::new(domain, content, command_runner)
Self::new(domain, content, command_runner)
} }
pub fn new_proxy<S: SocketSpec, STATIC: AsRef<Path>>( pub fn new_proxy<S: SocketSpec, STATIC: AsRef<Path>>(
domain: &'a str, domain: &'a str,
socket_path: S,
socket_path: &'_ S,
static_path: STATIC, static_path: STATIC,
command_runner: &'a C, command_runner: &'a C,
) -> Self { ) -> Self {
@ -163,7 +163,7 @@ location @proxy {{
proxy_content proxy_content
), ),
); );
NginxServer::new(domain, content, command_runner)
Self::new(domain, content, command_runner)
} }
pub fn new_php<SOCKET: AsRef<Path>, STATIC: AsRef<Path>>( pub fn new_php<SOCKET: AsRef<Path>, STATIC: AsRef<Path>>(
@ -177,7 +177,7 @@ location @proxy {{
domain, domain,
&(php_server_config_snippet(socket_path, static_path) + additional_config), &(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<S: AsRef<Path>>( pub fn new_static<S: AsRef<Path>>(
@ -195,7 +195,7 @@ location @proxy {{
static_path.as_ref().to_str().unwrap() 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 { 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<str>, P: AsRef<Path>> Symbol for NginxServer<'a, C, T, P> {
impl<C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> Symbol for NginxServer<'_, C, T, P> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.file.target_reached()? { if !self.file.target_reached()? {
return Ok(false); return Ok(false);
@ -239,9 +239,7 @@ impl<'a, C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> Symbol for NginxServer
} }
} }
impl<'a, C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> fmt::Display
for NginxServer<'a, C, T, P>
{
impl<C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> fmt::Display for NginxServer<'_, C, T, P> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Nginx server config") write!(f, "Nginx server config")
} }

4
src/symbols/npm.rs

@ -19,7 +19,7 @@ impl<'a, T: AsRef<Path>, C: CommandRunner> NpmInstall<'a, T, C> {
} }
} }
impl<'a, T: AsRef<Path>, C: CommandRunner> fmt::Display for NpmInstall<'a, T, C> {
impl<T: AsRef<Path>, C: CommandRunner> fmt::Display for NpmInstall<'_, T, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
@ -29,7 +29,7 @@ impl<'a, T: AsRef<Path>, C: CommandRunner> fmt::Display for NpmInstall<'a, T, C>
} }
} }
impl<'a, T: AsRef<Path>, C: CommandRunner> Symbol for NpmInstall<'a, T, C> {
impl<T: AsRef<Path>, C: CommandRunner> Symbol for NpmInstall<'_, T, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.target.as_ref().exists() { if !self.target.as_ref().exists() {
return Ok(false); return Ok(false);

4
src/symbols/owner.rs

@ -27,7 +27,7 @@ impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Owner<'a, C, D, U> {
} }
} }
impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Symbol for Owner<'a, C, D, U> {
impl<C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Symbol for Owner<'_, C, D, U> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(self.path.as_ref()).exists() { if !Path::new(self.path.as_ref()).exists() {
return Ok(false); return Ok(false);
@ -60,7 +60,7 @@ impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Symbol for Owner<'a, C
} }
} }
impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> fmt::Display for Owner<'a, C, D, U> {
impl<C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> fmt::Display for Owner<'_, C, D, U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!( write!(
f, f,

8
src/symbols/postgresql/database.rs

@ -28,17 +28,15 @@ impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> PostgreSQLDatabase<'a,
} }
} }
impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> fmt::Display
for PostgreSQLDatabase<'a, N, S, C>
impl<N: AsRef<str>, S: AsRef<str>, C: CommandRunner> fmt::Display
for PostgreSQLDatabase<'_, N, S, C>
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "PostgreSQL Database {}", self.name.as_ref()) write!(f, "PostgreSQL Database {}", self.name.as_ref())
} }
} }
impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> Symbol
for PostgreSQLDatabase<'a, N, S, C>
{
impl<N: AsRef<str>, S: AsRef<str>, C: CommandRunner> Symbol for PostgreSQLDatabase<'_, N, S, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok( Ok(
self self

75
src/symbols/postgresql/database_dump.rs

@ -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<str>, C: CommandRunner, S: Storage> {
db_name: N,
storage: S,
command_runner: &'a C,
}
impl<'a, N: AsRef<str>, 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<String, Box<dyn Error>> {
let b = self
.command_runner
.get_output("mariadb", args!["--skip-column-names", "-B", "-e", sql])?;
Ok(String::from_utf8(b)?)
}
}
impl<'a, N: AsRef<str>, 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<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
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<dyn Error>> {
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<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b>
where
Self: 'b,
{
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]
mod test {}

2
src/symbols/postgresql/mod.rs

@ -1,5 +1,3 @@
mod database; mod database;
mod database_dump;
pub use self::database::PostgreSQLDatabase; pub use self::database::PostgreSQLDatabase;
//pub use self::database_dump::PostgreSQLDump;

6
src/symbols/stored_directory.rs

@ -34,9 +34,7 @@ impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> StoredDirectory<'a, P, S,
} }
} }
impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> fmt::Display
for StoredDirectory<'a, P, S, C>
{
impl<P: AsRef<Path>, S: Storage, C: CommandRunner> fmt::Display for StoredDirectory<'_, P, S, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
@ -47,7 +45,7 @@ impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> fmt::Display
} }
} }
impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> Symbol for StoredDirectory<'a, P, S, C> {
impl<P: AsRef<Path>, S: Storage, C: CommandRunner> Symbol for StoredDirectory<'_, P, S, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let metadata = fs::metadata(self.path.as_ref()); let metadata = fs::metadata(self.path.as_ref());
// Check if dir exists // Check if dir exists

4
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<C: CommandRunner> Symbol for ReloadService<'_, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(true) 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<C: CommandRunner> fmt::Display for ReloadService<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Reload service {}", self.service) write!(f, "Reload service {}", self.service)
} }

20
src/symbols/systemd/user_service.rs

@ -29,14 +29,14 @@ impl From<io::Error> for UserServiceError<io::Error> {
impl<E: Error> Error for UserServiceError<E> { impl<E: Error> Error for UserServiceError<E> {
fn description(&self) -> &str { fn description(&self) -> &str {
match self { 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> { fn cause(&self) -> Option<&dyn Error> {
match self { match self {
UserServiceError::ExecError(ref e) => Some(e),
Self::ExecError(ref e) => Some(e),
_ => None, _ => None,
} }
} }
@ -126,9 +126,7 @@ WantedBy=default.target
} }
} }
impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner>
UserService<'a, S, U, C, R>
{
impl<S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> UserService<'_, S, U, C, R> {
fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> { fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
let mut tries = 5; let mut tries = 5;
loop { loop {
@ -176,8 +174,8 @@ impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner>
} }
} }
impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> Symbol
for UserService<'a, S, U, C, R>
impl<S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> Symbol
for UserService<'_, S, U, C, R>
{ {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !(self.config.target_reached()?) { if !(self.config.target_reached()?) {
@ -226,8 +224,8 @@ impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> Symbol
} }
} }
impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> fmt::Display
for UserService<'a, S, U, C, R>
impl<S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> fmt::Display
for UserService<'_, S, U, C, R>
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Systemd user service unit for {}", self.service_name) write!(f, "Systemd user service unit for {}", self.service_name)

10
src/symbols/systemd/user_session.rs

@ -14,13 +14,13 @@ pub enum SystemdUserSessionError<E: Error> {
impl<E: Error> Error for SystemdUserSessionError<E> { impl<E: Error> Error for SystemdUserSessionError<E> {
fn description(&self) -> &str { fn description(&self) -> &str {
match self { 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> { fn cause(&self) -> Option<&dyn Error> {
match self { match self {
SystemdUserSessionError::ExecError(ref e) => Some(e),
Self::ExecError(ref e) => Some(e),
_ => None, _ => None,
} }
} }
@ -46,7 +46,7 @@ impl<'a, U: AsRef<str>, C: CommandRunner> SystemdUserSession<'a, U, C> {
} }
} }
impl<'a, U: AsRef<str>, C: CommandRunner> Symbol for SystemdUserSession<'a, U, C> {
impl<U: AsRef<str>, C: CommandRunner> Symbol for SystemdUserSession<'_, U, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let mut path = PathBuf::from("/var/lib/systemd/linger"); let mut path = PathBuf::from("/var/lib/systemd/linger");
path.push(self.user_name.as_ref()); path.push(self.user_name.as_ref());
@ -72,7 +72,7 @@ impl<'a, U: AsRef<str>, C: CommandRunner> Symbol for SystemdUserSession<'a, U, C
} }
} }
impl<'a, U: AsRef<str>, C: CommandRunner> fmt::Display for SystemdUserSession<'a, U, C> {
impl<U: AsRef<str>, C: CommandRunner> fmt::Display for SystemdUserSession<'_, U, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Systemd user session for {}", self.user_name.as_ref()) write!(f, "Systemd user session for {}", self.user_name.as_ref())
} }

4
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<C: CommandRunner> fmt::Display for TlsCsr<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TlsCsr {}", self.domain) write!(f, "TlsCsr {}", self.domain)
} }
} }
impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
impl<C: CommandRunner> Symbol for TlsCsr<'_, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.get_csr_path().exists() { if !self.get_csr_path().exists() {
return Ok(false); return Ok(false);

6
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<C: CommandRunner> fmt::Display for TlsKey<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TlsKey {}", self.domain) write!(f, "TlsKey {}", self.domain)
} }
} }
impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
impl<C: CommandRunner> Symbol for TlsKey<'_, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.get_path().exists() { if !self.get_path().exists() {
return Ok(false); return Ok(false);
@ -54,7 +54,7 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
"-text".as_ref(), "-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<dyn Error>> { fn execute(&self) -> Result<(), Box<dyn Error>> {

4
src/symbols/tls/self_signed_cert.rs

@ -28,7 +28,7 @@ impl<'a, D: AsRef<str>, C: CommandRunner> SelfSignedTlsCert<'a, D, C> {
} }
} }
impl<'a, D: AsRef<str>, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a, D, C> {
impl<D: AsRef<str>, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'_, D, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SelfSignedTlsCert {}", self.domain.as_ref()) write!(f, "SelfSignedTlsCert {}", self.domain.as_ref())
} }
@ -36,7 +36,7 @@ impl<'a, D: AsRef<str>, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a,
const DAYS_IN_SECONDS: u32 = 24 * 60 * 60; const DAYS_IN_SECONDS: u32 = 24 * 60 * 60;
impl<'a, D: AsRef<str>, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, D, C> {
impl<D: AsRef<str>, C: CommandRunner> Symbol for SelfSignedTlsCert<'_, D, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.get_cert_path().exists() { if !self.get_cert_path().exists() {
return Ok(false); return Ok(false);

26
src/symbols/user.rs

@ -16,14 +16,14 @@ pub enum UserAdderError {
impl Error for UserAdderError { impl Error for UserAdderError {
fn description(&self) -> &str { fn description(&self) -> &str {
match self { 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 { match self {
UserAdderError::ImplError(ref e) => Some(e.as_ref()),
Self::ImplError(ref e) => Some(e.as_ref()),
_ => None, _ => None,
} }
} }
@ -31,7 +31,7 @@ impl Error for UserAdderError {
impl fmt::Display for UserAdderError { impl fmt::Display for UserAdderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.cause() {
match self.source() {
Some(e) => write!(f, "{} (cause: {})", self.description(), e), Some(e) => write!(f, "{} (cause: {})", self.description(), e),
None => write!(f, "{}", self.description()), None => write!(f, "{}", self.description()),
} }
@ -50,10 +50,10 @@ pub enum UserError {
impl Error for UserError { impl Error for UserError {
fn description(&self) -> &str { fn description(&self) -> &str {
match self { 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 { match self {
_ => None, _ => None,
} }
@ -62,7 +62,7 @@ impl Error for UserError {
impl fmt::Display for UserError { impl fmt::Display for UserError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.cause() {
match self.source() {
Some(e) => write!(f, "{} (cause: {})", self.description(), e), Some(e) => write!(f, "{} (cause: {})", self.description(), e),
None => write!(f, "{}", self.description()), 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<C: CommandRunner> UserAdder for SystemUserAdder<'_, C> {
fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> { fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> {
let output = self.command_runner.run_with_args( let output = self.command_runner.run_with_args(
"adduser", "adduser",
@ -152,11 +152,7 @@ impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
println!("{:?}", output); println!("{:?}", output);
Err(UserAdderError::AlreadyExists) Err(UserAdderError::AlreadyExists)
} }
Some(_) => {
println!("{:?}", output);
Err(UserAdderError::UnknownError)
}
None => {
_ => {
println!("{:?}", output); println!("{:?}", output);
Err(UserAdderError::UnknownError) Err(UserAdderError::UnknownError)
} }

6
src/symbols/wordpress/plugin.rs

@ -34,7 +34,7 @@ impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> WordpressPlugin<'a, P,
} }
} }
impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Symbol for WordpressPlugin<'a, P, N, R> {
impl<P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Symbol for WordpressPlugin<'_, P, N, R> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let base_path = self.get_path(); let base_path = self.get_path();
if !base_path.exists() { if !base_path.exists() {
@ -119,8 +119,8 @@ impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Symbol for WordpressPl
} }
} }
impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> fmt::Display
for WordpressPlugin<'a, P, N, R>
impl<P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> fmt::Display
for WordpressPlugin<'_, P, N, R>
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "WordpressPlugin {}", self.name.as_ref()) write!(f, "WordpressPlugin {}", self.name.as_ref())

18
src/symbols/wordpress/translation.rs

@ -33,7 +33,7 @@ impl<'a, C: AsRef<str>, R: CommandRunner> WordpressTranslation<'a, C, PathBuf, R
} }
} }
impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'a, C, D, R> {
impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'_, C, D, R> {
fn get_pairs(&self) -> Vec<(String, PathBuf)> { fn get_pairs(&self) -> Vec<(String, PathBuf)> {
let version_x = self let version_x = self
.version .version
@ -47,15 +47,13 @@ impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'
locale.to_lowercase().replace('_', "-") locale.to_lowercase().replace('_', "-")
}; };
let mut res = vec![]; let mut res = vec![];
for &(in_slug, out_slug) in [
for &(in_slug, out_slug) in &[
("", ""), ("", ""),
("cc/", "continents-cities-"), ("cc/", "continents-cities-"),
("admin/", "admin-"), ("admin/", "admin-"),
("admin/network/", "admin-network-"), ("admin/network/", "admin-network-"),
]
.iter()
{
for format in ["po", "mo"].iter() {
] {
for format in &["po", "mo"] {
res.push(( res.push((
format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format), 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() [self.path.as_ref(), format!("{}{}.{}", out_slug, self.locale.as_ref(), format).as_ref()].iter().collect()
@ -66,9 +64,7 @@ impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'
} }
} }
impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Symbol
for WordpressTranslation<'a, C, D, R>
{
impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Symbol for WordpressTranslation<'_, C, D, R> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let mut newest = String::new(); let mut newest = String::new();
let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap(); let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap();
@ -136,8 +132,8 @@ impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Symbol
} }
} }
impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> fmt::Display
for WordpressTranslation<'a, C, D, R>
impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> fmt::Display
for WordpressTranslation<'_, C, D, R>
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "WordpressTranslation {}", self.path.as_ref().display()) write!(f, "WordpressTranslation {}", self.path.as_ref().display())

Loading…
Cancel
Save