diff --git a/src/builder.rs b/src/builder.rs index 7a89085..481096d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -719,7 +719,7 @@ impl ImplementationBuilder> for DefaultBuilder { impl ImplementationBuilder> for DefaultBuilder { type Prerequisites = (); - fn prerequisites(resource: &PostgresqlDatabase) -> Self::Prerequisites { + fn prerequisites(_: &PostgresqlDatabase) -> Self::Prerequisites { () } diff --git a/src/command_runner.rs b/src/command_runner.rs index 5d8fd2f..b69e7ee 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -125,8 +125,8 @@ impl, 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) @@ -143,6 +143,8 @@ impl, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, .await .expect("Failed to write to stdin"); let res = child.wait_with_output().await; + drop(set_home); + drop(set_dbus); //println!("{:?}", res); res } diff --git a/src/locator.rs b/src/locator.rs index bdf17a7..739c8c3 100644 --- a/src/locator.rs +++ b/src/locator.rs @@ -15,23 +15,29 @@ use std::marker::PhantomData; use std::path::{Path, PathBuf}; pub trait Policy { + #[must_use] fn acme_user() -> &'static str { "acme" } + + #[must_use] fn user_home(user_name: &str) -> PathBuf { - format!("/home/{}", user_name).into() + Path::new("/home").join(user_name) } + #[must_use] fn user_name_for_domain(domain_name: &'_ str) -> String { domain_name.split('.').rev().fold(String::new(), |result, part| if result.is_empty() { result } else { result + "_" } + part) } + #[must_use] fn php_version() -> &'static str { "7.0" } + #[must_use] fn path_for_data(name: impl Display) -> PathBuf { - ("/root/data".as_ref() as &Path).join(format!("_{}", name)) + Path::new("/root/data").join(format!("_{}", name)) } } @@ -286,7 +292,7 @@ impl, POLICY> ResourceLocator> for DefaultLocator< resource: &ServeCustom, ) -> ( as Resource>::Artifact, Self::Prerequisites) { ( - PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)), + PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)), (), ) } @@ -298,7 +304,7 @@ impl, P, POLICY> ResourceLocator> for DefaultLocat resource: &ServePhp, ) -> ( as Resource>::Artifact, Self::Prerequisites) { ( - PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)), + PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)), (), ) } @@ -313,7 +319,7 @@ impl, P, POLICY> ResourceLocator> for DefaultL Self::Prerequisites, ) { ( - PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)), + PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)), (), ) } @@ -325,7 +331,7 @@ impl, POLICY> ResourceLocator> for DefaultLocator

, ) -> ( as Resource>::Artifact, Self::Prerequisites) { ( - PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)), + PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)), (), ) } @@ -340,7 +346,7 @@ impl, P, POLICY> ResourceLocator> for DefaultLo Self::Prerequisites, ) { ( - PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)), + PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)), (), ) } diff --git a/src/setup/runnable.rs b/src/setup/runnable.rs index 5c3a1c3..add3f49 100644 --- a/src/setup/runnable.rs +++ b/src/setup/runnable.rs @@ -32,6 +32,7 @@ where macro_rules! runnable_for_tuple { ( $($name:ident)* ) => ( + #[allow(clippy::let_unit_value)] #[async_trait(?Send)] #[allow(non_snake_case)] impl<$($name: Symbol + Debug,)*> Runnable for ($($name,)*) { @@ -117,7 +118,7 @@ mod test { async fn run_symbol( &self, symbol: &S, - logger: &L, + _logger: &L, force: bool, ) -> Result> { let run = force || !symbol.target_reached().await?; diff --git a/src/setup/setup.rs b/src/setup/setup.rs index 4efd0ab..842152b 100644 --- a/src/setup/setup.rs +++ b/src/setup/setup.rs @@ -201,7 +201,7 @@ mod test { async fn run_symbol( &self, symbol: &S, - logger: &L, + _logger: &L, force: bool, ) -> Result> { let run = force || !symbol.target_reached().await?; @@ -239,7 +239,7 @@ mod test { #[derive(Clone)] struct Artifacts; impl FromArtifact> for Artifacts { - fn from_artifact(from: ()) -> Self { + fn from_artifact(_from: ()) -> Self { Self } fn into_artifact(self) -> () { diff --git a/src/setup/symbol_runner.rs b/src/setup/symbol_runner.rs index 5448521..378cd90 100644 --- a/src/setup/symbol_runner.rs +++ b/src/setup/symbol_runner.rs @@ -17,27 +17,14 @@ pub trait SymbolRunner { ) -> Result>; } -#[derive(Debug)] -pub enum SymbolRunError { - Symbol(Box), - ExecuteDidNotReach(()), -} +#[derive(Debug, Default)] +pub struct ExecuteDidNotReachError; -impl Error for SymbolRunError { - fn cause(&self) -> Option<&dyn Error> { - match self { - Self::Symbol(ref e) => Some(&**e), - Self::ExecuteDidNotReach(_) => None, - } - } -} +impl Error for ExecuteDidNotReachError {} -impl fmt::Display for SymbolRunError { +impl fmt::Display for ExecuteDidNotReachError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Symbol(ref e) => write!(f, "{}", e), - Self::ExecuteDidNotReach(_) => write!(f, "Target not reached after executing symbol"), - } + write!(f, "Target not reached after executing symbol") } } @@ -45,7 +32,8 @@ impl fmt::Display for SymbolRunError { pub struct InitializingSymbolRunner; impl InitializingSymbolRunner { - pub fn new() -> Self { + #[must_use] + pub const fn new() -> Self { Self } @@ -64,7 +52,7 @@ impl InitializingSymbolRunner { if target_reached { Ok(()) } else { - Err(Box::new(SymbolRunError::ExecuteDidNotReach(()))) + Err(Box::new(ExecuteDidNotReachError)) } } } @@ -102,7 +90,8 @@ impl SymbolRunner for InitializingSymbolRunner { pub struct DelayingSymbolRunner(R); impl DelayingSymbolRunner { - pub fn new(symbol_runner: R) -> Self { + #[must_use] + pub const fn new(symbol_runner: R) -> Self { Self(symbol_runner) } } @@ -137,7 +126,8 @@ where pub struct DrySymbolRunner; impl DrySymbolRunner { - pub fn new() -> Self { + #[must_use] + pub const fn new() -> Self { Self } } @@ -172,7 +162,8 @@ impl SymbolRunner for DrySymbolRunner { pub struct ReportingSymbolRunner(R); impl ReportingSymbolRunner { - pub fn new(symbol_runner: R) -> Self { + #[must_use] + pub const fn new(symbol_runner: R) -> Self { Self(symbol_runner) } } @@ -251,6 +242,7 @@ mod test { T: Iterator>>, > DummySymbol { + #[must_use] fn new< IE: IntoIterator>>, IT: IntoIterator>>, diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index e2ad4a5..14593ba 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -63,7 +63,12 @@ impl, P: AsRef, S: AsRef, B: AsRef Result<(), Box> { - if !self.target.as_ref().exists() { + if self.target.as_ref().exists() { + self + .run_git(&["fetch", self.source.as_ref(), self.branch.as_ref()]) + .await?; + self.run_git(&["merge", "FETCH_HEAD"]).await?; + } else { self .command_runner .borrow() @@ -80,11 +85,6 @@ impl, P: AsRef, S: AsRef, B: AsRef, C: CommandRunner> Symbol for User { // adduser is not reentrant because finding the next uid // and creating the account is not an atomic operation let wait = WAIT.acquire().await; - self + let res = self .command_runner .run_successfully( "adduser", @@ -51,7 +51,9 @@ impl, C: CommandRunner> Symbol for User { self.user_name.as_ref(), ], ) - .await + .await; + drop(wait); + res } } diff --git a/src/to_artifact.rs b/src/to_artifact.rs index e158f07..e45cda9 100644 --- a/src/to_artifact.rs +++ b/src/to_artifact.rs @@ -17,6 +17,8 @@ macro_rules! to_artifact { for_each_tuple!(to_artifact); impl ToArtifact for Option { + // FIXME: https://github.com/rust-lang/rust-clippy/issues/2843 + #![allow(clippy::use_self)] type Artifact = Option; }