diff --git a/src/builder.rs b/src/builder.rs index 9ec4fb1..8cfa7e7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -33,9 +33,7 @@ use crate::symbols::wordpress::{ Plugin as WordpressPluginSymbol, Translation as WordpressTranslationSymbol, }; use crate::templates::nginx; -use crate::templates::php::{ - fpm_pool_config as php_fpm_pool_config, FpmPoolConfig as PhpFpmPoolConfig, -}; +use crate::templates::php::{fpm_pool_config as php_fpm_pool_config, FpmPoolConfig as PhpFpmPoolConfig}; use crate::templates::systemd::{ nodejs_service as systemd_nodejs_service, socket_service as systemd_socket_service, }; @@ -252,9 +250,7 @@ impl + Clone + Display> ImplementationBuilder> for } } -impl, C: Clone + Into> - ImplementationBuilder> for DefaultBuilder -{ +impl, C: Clone + Into> ImplementationBuilder> for DefaultBuilder { type Prerequisites = ( PhpFpmPool, CertChain, @@ -790,6 +786,6 @@ impl ImplementationBuilder> for DefaultBuilder { (): & as Resource>::Artifact, user_name: ::Artifact, ) -> Self::Implementation { - CronSymbol::new((user_name.0).0, &resource.1, &StdCommandRunner) + CronSymbol::new((user_name.0).0, resource.1.clone(), &StdCommandRunner) } } diff --git a/src/command_runner.rs b/src/command_runner.rs index 5be8ddc..5f37ca1 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -33,17 +33,17 @@ pub fn get_output(output: Output) -> Result, Box> { #[async_trait(?Send)] pub trait CommandRunner { - async fn run(&self, program: &str, args: &[&OsStr], stdin: &[u8]) -> IoResult; + async fn run(&self, program: &str, args: &[&OsStr], stdin: &str) -> IoResult; async fn run_with_args(&self, program: &str, args: &[&OsStr]) -> IoResult { - self.run(program, args, b"").await + self.run(program, args, "").await } async fn get_output(&self, program: &str, args: &[&OsStr]) -> Result, Box> { let output = self.run_with_args(program, args).await?; get_output(output) } async fn run_successfully(&self, program: &str, args: &[&OsStr]) -> Result<(), Box> { - is_success(self.run(program, args, b"").await)?; + is_success(self.run(program, args, "").await)?; Ok(()) } async fn get_stderr(&self, program: &str, args: &[&OsStr]) -> Result, Box> { @@ -56,7 +56,7 @@ pub struct StdCommandRunner; #[async_trait(?Send)] impl CommandRunner for StdCommandRunner { - async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult { + async fn run(&self, program: &str, args: &[&OsStr], input: &str) -> IoResult { //println!("{} {:?}", program, args); let mut child = Command::new(program) .args(args) @@ -67,7 +67,7 @@ impl CommandRunner for StdCommandRunner { .expect("Failed to spawn child process"); let stdin = child.stdin.as_mut().expect("Failed to open stdin"); stdin - .write_all(input) + .write_all(input.as_bytes()) .await .expect("Failed to write to stdin"); let res = child.wait_with_output().await; @@ -122,7 +122,7 @@ impl Drop for TempSetEnv<'_> { #[async_trait(?Send)] impl, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> { - async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult { + async fn run(&self, program: &str, args: &[&OsStr], input: &str) -> IoResult { let uid = get_user_by_name(self.user_name.as_ref()) .expect("User does not exist") .uid(); @@ -140,7 +140,7 @@ impl, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, .expect("Failed to spawn child process"); let stdin = child.stdin.as_mut().expect("Failed to open stdin"); stdin - .write_all(input) + .write_all(input.as_bytes()) .await .expect("Failed to write to stdin"); let res = child.wait_with_output().await; @@ -179,7 +179,7 @@ impl<'a, C> CommandRunner for SuCommandRunner<'a, C> where C: 'a + CommandRunner, { - async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult { + async fn run(&self, program: &str, args: &[&OsStr], input: &str) -> IoResult { let raw_new_args = [self.user_name, "-s", "/usr/bin/env", "--", program]; let mut new_args: Vec<&OsStr> = raw_new_args.iter().map(AsRef::as_ref).collect(); new_args.extend_from_slice(args); @@ -201,8 +201,8 @@ mod test { run(async { let args = args!["1"]; let start = Instant::now(); - let res = c.run("sleep", args, b"").fuse(); - let ps = c.run("ps", args![], b"").fuse(); + let res = c.run("sleep", args, "").fuse(); + let ps = c.run("ps", args![], "").fuse(); futures_util::pin_mut!(res, ps); loop { futures_util::select! { diff --git a/src/locator.rs b/src/locator.rs index 2b0561c..6633d4e 100644 --- a/src/locator.rs +++ b/src/locator.rs @@ -302,10 +302,7 @@ impl, P, C, POLICY> ResourceLocator> for Defaul type Prerequisites = (); fn locate( resource: &ServePhp, - ) -> ( - as Resource>::Artifact, - Self::Prerequisites, - ) { + ) -> ( as Resource>::Artifact, Self::Prerequisites) { ( PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)), (), diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 9b16405..d8837f5 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -147,7 +147,13 @@ impl Resource for ServeCustom { } #[derive(Debug, Hash, PartialEq, Eq)] -pub struct ServePhp(pub D, pub P, pub &'static str, pub String, pub C); +pub struct ServePhp( + pub D, + pub P, + pub &'static str, + pub String, + pub C, +); impl Resource for ServePhp { type Artifact = PathArtifact; } @@ -313,18 +319,7 @@ default_resources!( WordpressTranslation: WordpressTranslation, ); -pub fn serve_php, C: Into>( - domain: D, - path: P, - root_filename: &'static str, - nginx_config: impl Into, - pool_config: C, -) -> ServePhp { +pub fn serve_php, C: Into>(domain: D, path: P, root_filename: &'static str, nginx_config: impl Into, pool_config: C) -> ServePhp { ServePhp( - domain, - path.into(), - root_filename, - nginx_config.into(), - pool_config.into(), - ) + domain, path.into(), root_filename, nginx_config.into(), pool_config.into()) } diff --git a/src/symbols/cron.rs b/src/symbols/cron.rs index 45571ed..2a452ce 100644 --- a/src/symbols/cron.rs +++ b/src/symbols/cron.rs @@ -21,13 +21,13 @@ impl<'r, U, R> Cron<'r, String, U, R> { } #[async_trait(?Send)] -impl, U: AsRef, R: CommandRunner> Symbol for Cron<'_, C, U, R> { +impl, U: AsRef, R: CommandRunner> Symbol for Cron<'_, C, U, R> { async fn target_reached(&self) -> Result> { let tab = self .command_runner .get_output("crontab", args!["-l", "-u", self.user.as_ref()]) .await?; - Ok(tab == self.content.as_ref()) + Ok(tab == self.content.as_ref().as_bytes()) } async fn execute(&self) -> Result<(), Box> { diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index f5399c7..4063aa9 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -110,9 +110,9 @@ mod test { } #[async_trait(?Send)] impl CommandRunner for DummyCommandRunner { - async fn run(&self, program: &str, args: &[&OsStr], stdin: &[u8]) -> IoResult { + async fn run(&self, program: &str, args: &[&OsStr], stdin: &str) -> IoResult { assert_eq!(program, "git"); - assert_eq!(stdin, b""); + assert_eq!(stdin, ""); sleep(Duration::from_millis(50)).await; self .args diff --git a/src/templates/php.rs b/src/templates/php.rs index 7bd7695..d131fe2 100644 --- a/src/templates/php.rs +++ b/src/templates/php.rs @@ -27,10 +27,7 @@ impl From for FpmPoolConfig { impl FpmPoolConfig { pub fn new(max_children: usize, custom: impl Into) -> Self { - Self { - max_children, - custom: Some(custom.into()), - } + Self { max_children, custom: Some(custom.into()) } } }