From 64e20b371bcd6c8045d1411e60727f3745932612 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 24 Sep 2019 21:56:31 +0200 Subject: [PATCH] Update rustfmt --- rustfmt.toml | 2 + src/command_runner.rs | 12 +++--- src/schema.rs | 10 ++--- src/storage.rs | 4 +- src/symbols/acme/account_key.rs | 8 ++-- src/symbols/acme/cert.rs | 22 +++++----- src/symbols/acme/chain.rs | 20 ++++----- src/symbols/acme/user.rs | 16 ++----- src/symbols/cron.rs | 4 +- src/symbols/file.rs | 4 +- src/symbols/git/checkout.rs | 10 ++--- src/symbols/git/submodules.rs | 6 +-- src/symbols/hook.rs | 2 +- src/symbols/list.rs | 57 +++++++++++-------------- src/symbols/mariadb/database.rs | 12 +++--- src/symbols/mariadb/database_dump.rs | 10 ++--- src/symbols/mariadb/user.rs | 21 ++++----- src/symbols/nginx/server.rs | 4 +- src/symbols/npm.rs | 4 +- src/symbols/postgresql/database.rs | 19 +++++---- src/symbols/postgresql/database_dump.rs | 10 ++--- src/symbols/stored_directory.rs | 34 ++++++--------- src/symbols/systemd/user_service.rs | 30 ++++++------- src/symbols/tls/csr.rs | 14 +++--- src/symbols/tls/key.rs | 6 +-- src/symbols/tls/self_signed_cert.rs | 8 ++-- src/symbols/user.rs | 4 +- src/symbols/wordpress/plugin.rs | 18 ++++---- src/symbols/wordpress/translation.rs | 14 +++--- 29 files changed, 179 insertions(+), 206 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index b196eaa..c55fc1d 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,3 @@ tab_spaces = 2 +use_try_shorthand = true +use_field_init_shorthand = true diff --git a/src/command_runner.rs b/src/command_runner.rs index 7bf6181..0b73422 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -24,9 +24,9 @@ pub trait CommandRunner { program: &str, args: &[&S], ) -> Result, Box> { - let output = try!(self.run_with_args(program, args)); + let output = self.run_with_args(program, args)?; if !output.status.success() { - return Err(try!(String::from_utf8(output.stderr)).into()); + return Err(String::from_utf8(output.stderr)?.into()); } Ok(output.stdout) } @@ -35,9 +35,9 @@ pub trait CommandRunner { program: &str, args: &[&S], ) -> Result, Box> { - let output = try!(self.run_with_args(program, args)); + let output = self.run_with_args(program, args)?; if !output.status.success() { - return Err(try!(String::from_utf8(output.stderr)).into()); + return Err(String::from_utf8(output.stderr)?.into()); } Ok(output.stderr) } @@ -46,11 +46,11 @@ pub trait CommandRunner { program: &str, args: &[&S], ) -> Result<(), Box> { - let output = try!(self.run_with_args(program, args)); + let output = self.run_with_args(program, args)?; if output.status.success() { Ok(()) } else { - Err(try!(String::from_utf8(output.stderr)).into()) + Err(String::from_utf8(output.stderr)?.into()) } } } diff --git a/src/schema.rs b/src/schema.rs index 9f40dd7..ba430a3 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -51,14 +51,14 @@ impl InitializingSymbolRunner { impl SymbolRunner for InitializingSymbolRunner { fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { let mut logger = self.logger.borrow_mut(); - let target_reached = try!(symbol.target_reached()); + let target_reached = symbol.target_reached()?; if target_reached { logger.write(format!("{} already reached", symbol).as_str()); } else { logger.debug(format!("Symbol reports target_reached: {:?}", target_reached).as_str()); logger.write(format!("Executing {}", symbol).as_str()); - try!(symbol.execute()); - let target_reached = try!(symbol.target_reached()); + symbol.execute()?; + let target_reached = symbol.target_reached()?; logger.debug( format!( "Symbol reports target_reached: {:?} (should be true)", @@ -89,7 +89,7 @@ impl DrySymbolRunner { impl SymbolRunner for DrySymbolRunner { fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { let mut logger = self.logger.borrow_mut(); - let target_reached = try!(symbol.target_reached()); + let target_reached = symbol.target_reached()?; logger.debug(format!("Symbol reports target_reached: {:?}", target_reached).as_str()); if !target_reached { logger.write(format!("Would execute {}", symbol).as_str()); @@ -196,7 +196,7 @@ where fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { for resource in symbol.get_prerequisites() { if let Some(dep) = self.1.get_symbol(&resource) { - try!(dep.as_action(self).run()); + dep.as_action(self).run()?; } } self.0.run_symbol(&*symbol) diff --git a/src/storage.rs b/src/storage.rs index 1b61334..450ce05 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -36,12 +36,12 @@ impl Storage for SimpleStorage { } fn read_filename(&self) -> Result> { - Ok(self.get_path(Some(try!(self.recent_date())))) + Ok(self.get_path(Some(self.recent_date()?))) } fn recent_date(&self) -> Result> { let dir = self.get_path(None); - try!(read_dir(dir)) + read_dir(dir)? .map(|entry| { entry .ok() diff --git a/src/symbols/acme/account_key.rs b/src/symbols/acme/account_key.rs index 37373d8..2b0226d 100644 --- a/src/symbols/acme/account_key.rs +++ b/src/symbols/acme/account_key.rs @@ -36,7 +36,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> { if !self.path.exists() { return Ok(false); } - let stdout = try!(self.command_runner.get_output( + let stdout = self.command_runner.get_output( "openssl", &[ "rsa".as_ref(), @@ -44,9 +44,9 @@ impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> { self.path.as_os_str(), "-noout".as_ref(), "-check".as_ref(), - "-text".as_ref() - ] - )); + "-text".as_ref(), + ], + )?; Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) } diff --git a/src/symbols/acme/cert.rs b/src/symbols/acme/cert.rs index 480b593..2796b9b 100644 --- a/src/symbols/acme/cert.rs +++ b/src/symbols/acme/cert.rs @@ -45,7 +45,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { return Ok(false); } - let output = try!(self.command_runner.run_with_args( + let output = self.command_runner.run_with_args( "openssl", &[ "x509", @@ -54,9 +54,9 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { "-noout", "-subject", "-checkend", - &(30 * DAYS_IN_SECONDS).to_string() - ] - )); + &(30 * DAYS_IN_SECONDS).to_string(), + ], + )?; if output.status.success() && output.stdout == format!( @@ -85,12 +85,12 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { { Ok(false) } else { - Err(try!(String::from_utf8(output.stderr)).into()) + Err(String::from_utf8(output.stderr)?.into()) } } fn execute(&self) -> Result<(), Box> { - let output = try!(self.command_runner.get_output( + let output = self.command_runner.get_output( "acme-tiny", &[ "--account-key", @@ -98,11 +98,11 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { "--csr", &self.get_csr_path(), "--acme-dir", - "/home/acme/challenges/" - ] - )); - let mut file = try!(FsFile::create(self.get_cert_path())); - try!(file.write_all(&output)); + "/home/acme/challenges/", + ], + )?; + let mut file = FsFile::create(self.get_cert_path())?; + file.write_all(&output)?; Ok(()) } diff --git a/src/symbols/acme/chain.rs b/src/symbols/acme/chain.rs index ebfb0e2..c8c0ddc 100644 --- a/src/symbols/acme/chain.rs +++ b/src/symbols/acme/chain.rs @@ -45,7 +45,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> { return Ok(false); } - let stdout = try!(self.command_runner.get_output( + let stdout = self.command_runner.get_output( "openssl", &[ "x509", @@ -54,9 +54,9 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> { "-noout", "-subject", "-checkend", - &(30 * DAYS_IN_SECONDS).to_string() - ] - )); + &(30 * DAYS_IN_SECONDS).to_string(), + ], + )?; if stdout != format!( "subject=CN = {}\nCertificate will not expire\n", @@ -84,15 +84,15 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> { } fn execute(&self) -> Result<(), Box> { - let output = try!(self.command_runner.get_output( + let output = self.command_runner.get_output( "cat", &[ self.get_single_cert_path().as_ref(), - "/home/acme/lets_encrypt_x3_cross_signed.pem" - ] - )); - let mut file = try!(FsFile::create(self.get_cert_chain_path())); - try!(file.write_all(&output)); + "/home/acme/lets_encrypt_x3_cross_signed.pem", + ], + )?; + let mut file = FsFile::create(self.get_cert_chain_path())?; + file.write_all(&output)?; Ok(()) } diff --git a/src/symbols/acme/user.rs b/src/symbols/acme/user.rs index fed9350..927469d 100644 --- a/src/symbols/acme/user.rs +++ b/src/symbols/acme/user.rs @@ -63,10 +63,7 @@ pub fn new<'a, S: Into>, C: CommandRunner, P: 'a + Deref>, C: CommandRunner, P: 'a + Deref, { fn target_reached(&self) -> Result> { - let tab = try!(self + let tab = self .command_runner - .get_output("crontab", &["-l", "-u", &self.user])); + .get_output("crontab", &["-l", "-u", &self.user])?; return Ok(tab == self.content.bytes().collect::>()); } diff --git a/src/symbols/file.rs b/src/symbols/file.rs index 0cb3bcb..dcc1ce3 100644 --- a/src/symbols/file.rs +++ b/src/symbols/file.rs @@ -57,8 +57,8 @@ where } fn execute(&self) -> Result<(), Box> { - let mut file = try!(FsFile::create(self.path.as_ref())); - try!(file.write_all(self.content.as_bytes())); + let mut file = FsFile::create(self.path.as_ref())?; + file.write_all(self.content.as_bytes())?; Ok(()) } diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index e3e82ee..42e9d7e 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -56,10 +56,10 @@ impl<'a, C: CommandRunner, T: AsRef> Symbol for GitCheckout<'a, C, T> { Err(Box::new(e)) }; } - try!(self._run_in_target_repo(&["fetch", self.source, self.branch])); + self._run_in_target_repo(&["fetch", self.source, self.branch])?; // git rev-list resolves tag objects - let fetch_head = try!(self._run_in_target_repo(&["rev-list", "-1", "FETCH_HEAD"])); - let head = try!(self._run_in_target_repo(&["rev-list", "-1", "HEAD"])); + let fetch_head = self._run_in_target_repo(&["rev-list", "-1", "FETCH_HEAD"])?; + let head = self._run_in_target_repo(&["rev-list", "-1", "HEAD"])?; Ok(fetch_head == head) } @@ -78,8 +78,8 @@ impl<'a, C: CommandRunner, T: AsRef> Symbol for GitCheckout<'a, C, T> { ], ); } - try!(self._run_in_target_repo(&["fetch", self.source, self.branch])); - try!(self._run_in_target_repo(&["merge", "FETCH_HEAD"])); + self._run_in_target_repo(&["fetch", self.source, self.branch])?; + self._run_in_target_repo(&["merge", "FETCH_HEAD"])?; Ok(()) } diff --git a/src/symbols/git/submodules.rs b/src/symbols/git/submodules.rs index 0437f0f..1adc7fc 100644 --- a/src/symbols/git/submodules.rs +++ b/src/symbols/git/submodules.rs @@ -38,9 +38,7 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> { if !Path::new(self.target).exists() { return Ok(false); } - let output = try!(String::from_utf8(try!( - self._run_in_target_repo(&["submodule", "status"]) - ))); + let output = String::from_utf8(self._run_in_target_repo(&["submodule", "status"])?)?; Ok( output .lines() @@ -49,7 +47,7 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> { } fn execute(&self) -> Result<(), Box> { - try!(self._run_in_target_repo(&["submodule", "update", "--init"])); + self._run_in_target_repo(&["submodule", "update", "--init"])?; Ok(()) } diff --git a/src/symbols/hook.rs b/src/symbols/hook.rs index 319d75d..d81e1d2 100644 --- a/src/symbols/hook.rs +++ b/src/symbols/hook.rs @@ -40,7 +40,7 @@ where } fn execute(&self) -> Result<(), Box> { - try!(self.a.execute()); + self.a.execute()?; self.b.execute() } diff --git a/src/symbols/list.rs b/src/symbols/list.rs index 4a2c019..19c6ae0 100644 --- a/src/symbols/list.rs +++ b/src/symbols/list.rs @@ -17,7 +17,7 @@ impl<'a> List<'a> { impl<'a> Symbol for List<'a> { fn target_reached(&self) -> Result> { for symbol in &self.symbols { - if !try!(symbol.target_reached()) { + if !symbol.target_reached()? { return Ok(false); } } @@ -26,7 +26,7 @@ impl<'a> Symbol for List<'a> { fn execute(&self) -> Result<(), Box> { for symbol in &self.symbols { - try!(symbol.execute()); + symbol.execute()?; } Ok(()) } @@ -87,73 +87,64 @@ impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol> From<(A, B, C)> for Lis } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol> From<(A, B, C, D)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol> From<(A, B, C, D)> for List<'a> { fn from((a, b, c, d): (A, B, C, D)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol> From<(A, B, C, D, E)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol> From<(A, B, C, D, E)> for List<'a> { fn from((a, b, c, d, e): (A, B, C, D, E)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol> From<(A, B, C, D, E, F)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol> From<(A, B, C, D, E, F)> for List<'a> { fn from((a, b, c, d, e, f): (A, B, C, D, E, F)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol> From<(A, B, C, D, E, F, G)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol> From<(A, B, C, D, E, F, G)> for List<'a> { fn from((a, b, c, d, e, f, g): (A, B, C, D, E, F, G)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol> From<(A, B, C, D, E, F, G, H)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol> From<(A, B, C, D, E, F, G, H)> for List<'a> { fn from((a, b, c, d, e, f, g, h): (A, B, C, D, E, F, G, H)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K)> for List<'a> { fn from((a, b, c, d, e, f, g, h, i, j, k): (A, B, C, D, E, F, G, H, I, J, K)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L)> for List<'a> { fn from((a, b, c, d, e, f, g, h, i, j, k, l): (A, B, C, D, E, F, G, H, I, J, K, L)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M)> for List<'a> { fn from((a, b, c, d, e, f, g, h, i, j, k, l, m): (A, B, C, D, E, F, G, H, I, J, K, L, M)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l), Box::new(m)]) } } -impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol, N: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N)> - for List<'a> -{ +#[rustfmt::skip] +impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol, N: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N)> for List<'a> { fn from((a, b, c, d, e, f, g, h, i, j, k, l, m, n): (A, B, C, D, E, F, G, H, I, J, K, L, M, N)) -> Self { Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l), Box::new(m), Box::new(n)]) } @@ -173,7 +164,7 @@ impl<'a> SymbolListAction<'a> { impl<'a> Action for SymbolListAction<'a> { fn run(&self) -> Result<(), Box> { for symbol in self.symbols { - try!(symbol.as_action(self.runner).run()); + symbol.as_action(self.runner).run()?; } Ok(()) } @@ -192,7 +183,7 @@ impl<'a> ListAction<'a> { impl<'a> Action for ListAction<'a> { fn run(&self) -> Result<(), Box> { for action in &self.actions { - try!(action.run()); + action.run()?; } Ok(()) } @@ -200,9 +191,9 @@ impl<'a> Action for ListAction<'a> { impl<'a> fmt::Display for List<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(write!(f, "List [ ")); + write!(f, "List [ ")?; for symbol in &self.symbols { - try!(write!(f, "{} ", symbol)); + write!(f, "{} ", symbol)?; } write!(f, "]") } diff --git a/src/symbols/mariadb/database.rs b/src/symbols/mariadb/database.rs index 5d5501c..83cf8da 100644 --- a/src/symbols/mariadb/database.rs +++ b/src/symbols/mariadb/database.rs @@ -21,10 +21,10 @@ impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> { } fn run_sql(&self, sql: &str) -> Result> { - let b = try!(self + let b = self .command_runner - .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); - Ok(try!(String::from_utf8(b))) + .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?; + Ok(String::from_utf8(b)?) } } @@ -37,13 +37,15 @@ impl<'a, C: CommandRunner> fmt::Display for MariaDBDatabase<'a, C> { impl<'a, C: CommandRunner> Symbol for MariaDBDatabase<'a, C> { fn target_reached(&self) -> Result> { Ok( - try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_end() + self + .run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))? + .trim_end() == self.db_name, ) } fn execute(&self) -> Result<(), Box> { - try!(self.run_sql(&format!("CREATE DATABASE {}", self.db_name))); + self.run_sql(&format!("CREATE DATABASE {}", self.db_name))?; self.command_runner.run_successfully( "sh", &[ diff --git a/src/symbols/mariadb/database_dump.rs b/src/symbols/mariadb/database_dump.rs index f5551be..6577c6a 100644 --- a/src/symbols/mariadb/database_dump.rs +++ b/src/symbols/mariadb/database_dump.rs @@ -27,10 +27,10 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> } fn run_sql(&self, sql: &str) -> Result> { - let b = try!(self + let b = self .command_runner - .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); - Ok(try!(String::from_utf8(b))) + .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?; + Ok(String::from_utf8(b)?) } } @@ -42,12 +42,12 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> fmt::Display for DatabaseD impl<'a, N: AsRef, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { fn target_reached(&self) -> Result> { - let dump_date = try!(self.storage.recent_date()); + let dump_date = self.storage.recent_date()?; let modified_date = try!(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(try!(u64::from_str(modified_date.trim_end())) <= dump_date) + Ok(u64::from_str(modified_date.trim_end())? <= dump_date) } fn execute(&self) -> Result<(), Box> { diff --git a/src/symbols/mariadb/user.rs b/src/symbols/mariadb/user.rs index 7ef9467..ca923ab 100644 --- a/src/symbols/mariadb/user.rs +++ b/src/symbols/mariadb/user.rs @@ -20,10 +20,10 @@ impl<'a, C: CommandRunner> MariaDBUser<'a, C> { } fn run_sql(&self, sql: &str) -> Result> { - let b = try!(self + let b = self .command_runner - .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); - Ok(try!(String::from_utf8(b))) + .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?; + Ok(String::from_utf8(b)?) } } @@ -36,20 +36,21 @@ impl<'a, C: CommandRunner> fmt::Display for MariaDBUser<'a, C> { impl<'a, C: CommandRunner> Symbol for MariaDBUser<'a, C> { fn target_reached(&self) -> Result> { Ok( - try!(self.run_sql(&format!( - "SELECT User FROM mysql.user WHERE User = '{}' AND plugin = 'unix_socket'", - self.user_name - ))) - .trim_end() + self + .run_sql(&format!( + "SELECT User FROM mysql.user WHERE User = '{}' AND plugin = 'unix_socket'", + self.user_name + ))? + .trim_end() == self.user_name, ) } fn execute(&self) -> Result<(), Box> { - try!(self.run_sql(&format!( + self.run_sql(&format!( "GRANT ALL ON {0}.* TO {0} IDENTIFIED VIA unix_socket", self.user_name - ))); + ))?; Ok(()) } diff --git a/src/symbols/nginx/server.rs b/src/symbols/nginx/server.rs index 1d0cf5b..75c67ec 100644 --- a/src/symbols/nginx/server.rs +++ b/src/symbols/nginx/server.rs @@ -208,7 +208,7 @@ where T: Deref, { fn target_reached(&self) -> Result> { - if !try!(self.file.target_reached()) { + if !self.file.target_reached()? { return Ok(false); } // TODO: Could try to find out if the server is in the live config @@ -216,7 +216,7 @@ where } fn execute(&self) -> Result<(), Box> { - try!(self.file.execute()); + self.file.execute()?; self .command_runner .run_successfully("systemctl", &["reload-or-restart", "nginx"]) diff --git a/src/symbols/npm.rs b/src/symbols/npm.rs index 3e05f69..f573e74 100644 --- a/src/symbols/npm.rs +++ b/src/symbols/npm.rs @@ -30,9 +30,9 @@ impl<'a, C: CommandRunner> Symbol for NpmInstall<'a, C> { if !Path::new(self.target).exists() { return Ok(false); } - let result = try!(self + let result = self .command_runner - .run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)])); + .run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)])?; Ok( result.status.success() && !String::from_utf8(result.stdout) diff --git a/src/symbols/postgresql/database.rs b/src/symbols/postgresql/database.rs index 16bbcea..7439d12 100644 --- a/src/symbols/postgresql/database.rs +++ b/src/symbols/postgresql/database.rs @@ -21,11 +21,11 @@ impl<'a, C: CommandRunner> PostgreSQLDatabase<'a, C> { } fn run_sql(&self, sql: &str) -> Result> { - let b = try!(self.command_runner.get_output( + let b = self.command_runner.get_output( "su", - &["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)] - )); - Ok(try!(String::from_utf8(b))) + &["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)], + )?; + Ok(String::from_utf8(b)?) } } @@ -38,11 +38,12 @@ impl<'a, C: CommandRunner> fmt::Display for PostgreSQLDatabase<'a, C> { impl<'a, C: CommandRunner> Symbol for PostgreSQLDatabase<'a, C> { fn target_reached(&self) -> Result> { Ok( - try!(self.run_sql(&format!( - "SELECT datname FROM pg_database WHERE datname LIKE '{}'", - self.name - ))) - .trim() + self + .run_sql(&format!( + "SELECT datname FROM pg_database WHERE datname LIKE '{}'", + self.name + ))? + .trim() == self.name, ) } diff --git a/src/symbols/postgresql/database_dump.rs b/src/symbols/postgresql/database_dump.rs index f5551be..6577c6a 100644 --- a/src/symbols/postgresql/database_dump.rs +++ b/src/symbols/postgresql/database_dump.rs @@ -27,10 +27,10 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> } fn run_sql(&self, sql: &str) -> Result> { - let b = try!(self + let b = self .command_runner - .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); - Ok(try!(String::from_utf8(b))) + .get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?; + Ok(String::from_utf8(b)?) } } @@ -42,12 +42,12 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> fmt::Display for DatabaseD impl<'a, N: AsRef, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { fn target_reached(&self) -> Result> { - let dump_date = try!(self.storage.recent_date()); + let dump_date = self.storage.recent_date()?; let modified_date = try!(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(try!(u64::from_str(modified_date.trim_end())) <= dump_date) + Ok(u64::from_str(modified_date.trim_end())? <= dump_date) } fn execute(&self) -> Result<(), Box> { diff --git a/src/symbols/stored_directory.rs b/src/symbols/stored_directory.rs index 996c476..7ed933f 100644 --- a/src/symbols/stored_directory.rs +++ b/src/symbols/stored_directory.rs @@ -71,35 +71,31 @@ where ))); } - let dump_date = try!(self.storage.recent_date()); - let output = try!(self.command_runner.get_output( + let dump_date = self.storage.recent_date()?; + let output = self.command_runner.get_output( "sh", &[ "-c", &format!( "find {} -printf '%T@\\n' | sort -r | head -n1 | grep '^[0-9]\\+' -o", self.path - ) - ] - )); - let modified_date = try!(u64::from_str(try!(String::from_utf8(output)).trim_end())); + ), + ], + )?; + let modified_date = u64::from_str(String::from_utf8(output)?.trim_end())?; if if self.dir == StorageDirection::Save { modified_date > dump_date } else { dump_date > modified_date } { - let output = try!(self.command_runner.run_with_args( + let output = self.command_runner.run_with_args( "diff", - &[ - "-rq", - &try!(self.storage.read_filename()), - self.path.borrow() - ] - )); + &["-rq", &self.storage.read_filename()?, self.path.borrow()], + )?; match output.status.code() { Some(0) => Ok(true), Some(1) => Ok(false), - _ => Err(try!(String::from_utf8(output.stderr)).into()), + _ => Err(String::from_utf8(output.stderr)?.into()), } } else { Ok(true) @@ -108,16 +104,12 @@ where fn execute(&self) -> Result<(), Box> { if self.dir == StorageDirection::Load { - try!(self + self .command_runner - .run_successfully("rm", &["-rf", self.path.borrow()])); + .run_successfully("rm", &["-rf", self.path.borrow()])?; self.command_runner.run_successfully( "cp", - &[ - "-a", - &try!(self.storage.read_filename()), - self.path.borrow(), - ], + &["-a", &self.storage.read_filename()?, self.path.borrow()], ) } else { self.command_runner.run_successfully( diff --git a/src/symbols/systemd/user_service.rs b/src/symbols/systemd/user_service.rs index a7a6081..72a2d58 100644 --- a/src/symbols/systemd/user_service.rs +++ b/src/symbols/systemd/user_service.rs @@ -43,9 +43,9 @@ impl Error for UserServiceError { impl fmt::Display for UserServiceError { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(write!(f, "{}", self.description())); + write!(f, "{}", self.description())?; if let UserServiceError::ActivationFailed(Ok(ref log)) = self { - try!(write!(f, ": {:?}", log)); + write!(f, ": {:?}", log)?; }; Ok(()) } @@ -126,19 +126,15 @@ where fn systemctl_wait_for_dbus(&self, args: &[&str]) -> Result> { let mut tries = 5; loop { - let result = try!(self.command_runner.run_with_args("systemctl", args)); + let result = self.command_runner.run_with_args("systemctl", args)?; if !result.status.success() { - let raw_stderr = try!(String::from_utf8(result.stderr)); + let raw_stderr = String::from_utf8(result.stderr)?; let stderr = raw_stderr.trim_end(); if stderr != "Failed to connect to bus: No such file or directory" { return Err(stderr.into()); } } else { - return Ok( - try!(String::from_utf8(result.stdout)) - .trim_end() - .to_string(), - ); + return Ok(String::from_utf8(result.stdout)?.trim_end().to_string()); } tries -= 1; if tries == 0 { @@ -150,13 +146,13 @@ where fn check_if_service(&self) -> Result> { loop { - let active_state = try!(self.systemctl_wait_for_dbus(&[ + let active_state = self.systemctl_wait_for_dbus(&[ "--user", "show", "--property", "ActiveState", - self.service_name - ])); + self.service_name, + ])?; match active_state.as_ref() { "ActiveState=activating" => sleep(Duration::from_millis(500)), "ActiveState=active" => return Ok(true), @@ -180,18 +176,18 @@ where R: CommandRunner, { fn target_reached(&self) -> Result> { - if !(try!(self.file.target_reached())) { + if !(self.file.target_reached()?) { return Ok(false); } self.check_if_service() } fn execute(&self) -> Result<(), Box> { - try!(self.file.execute()); - try!(self.systemctl_wait_for_dbus(&["--user", "enable", self.service_name])); - try!(self.systemctl_wait_for_dbus(&["--user", "restart", self.service_name])); + self.file.execute()?; + self.systemctl_wait_for_dbus(&["--user", "enable", self.service_name])?; + self.systemctl_wait_for_dbus(&["--user", "restart", self.service_name])?; - if !(try!(self.check_if_service())) { + if !(self.check_if_service()?) { return Err(Box::new( UserServiceError::GenericError as UserServiceError, )); diff --git a/src/symbols/tls/csr.rs b/src/symbols/tls/csr.rs index 091f92b..4df226f 100644 --- a/src/symbols/tls/csr.rs +++ b/src/symbols/tls/csr.rs @@ -41,15 +41,15 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> { return Ok(false); } - let output = try!(self.command_runner.get_stderr( + let output = self.command_runner.get_stderr( "openssl", - &["req", "-in", &self.get_csr_path(), "-noout", "-verify"] - )); + &["req", "-in", &self.get_csr_path(), "-noout", "-verify"], + )?; Ok(output == b"verify OK\n") } fn execute(&self) -> Result<(), Box> { - try!(self.command_runner.run_successfully( + self.command_runner.run_successfully( "openssl", &[ "req", @@ -60,9 +60,9 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> { "-out", &self.get_csr_path(), "-subj", - &format!("/CN={}", self.domain) - ] - )); + &format!("/CN={}", self.domain), + ], + )?; Ok(()) } diff --git a/src/symbols/tls/key.rs b/src/symbols/tls/key.rs index 4f69a52..d347963 100644 --- a/src/symbols/tls/key.rs +++ b/src/symbols/tls/key.rs @@ -40,10 +40,10 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> { return Ok(false); } - let output = try!(self.command_runner.get_output( + let output = self.command_runner.get_output( "openssl", - &["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"] - )); + &["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"], + )?; Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) } diff --git a/src/symbols/tls/self_signed_cert.rs b/src/symbols/tls/self_signed_cert.rs index 0895cb3..cf09fea 100644 --- a/src/symbols/tls/self_signed_cert.rs +++ b/src/symbols/tls/self_signed_cert.rs @@ -42,7 +42,7 @@ impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> { if !Path::new(&self.get_cert_path()).exists() { return Ok(false); } - let output = try!(self.command_runner.run_with_args( + let output = self.command_runner.run_with_args( "openssl", &[ "x509", @@ -51,9 +51,9 @@ impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> { "-noout", "-subject", "-checkend", - &(30 * DAYS_IN_SECONDS).to_string() - ] - )); + &(30 * DAYS_IN_SECONDS).to_string(), + ], + )?; println!("{}", output.status.code().unwrap()); match output.status.code() { Some(0) => Ok( diff --git a/src/symbols/user.rs b/src/symbols/user.rs index 24bfecf..f2524c5 100644 --- a/src/symbols/user.rs +++ b/src/symbols/user.rs @@ -93,9 +93,9 @@ impl<'a, C: CommandRunner, A: 'a + UserAdder> fmt::Display for User<'a, C, A> { impl<'a, C: CommandRunner, A: 'a + UserAdder> Symbol for User<'a, C, A> { fn target_reached(&self) -> Result> { - let output = try!(self + let output = self .command_runner - .run_with_args("getent", &["passwd", &*self.user_name])); + .run_with_args("getent", &["passwd", &*self.user_name])?; match output.status.code() { Some(2) => Ok(false), Some(0) => Ok(true), diff --git a/src/symbols/wordpress/plugin.rs b/src/symbols/wordpress/plugin.rs index 2530ba9..0f2fe79 100644 --- a/src/symbols/wordpress/plugin.rs +++ b/src/symbols/wordpress/plugin.rs @@ -76,7 +76,7 @@ where } } } - let upstream = try!(self.command_runner.get_output( + let upstream = self.command_runner.get_output( "curl", &[ "--form", @@ -84,21 +84,21 @@ where r###"plugins={{"plugins":{{"{0}/{0}.php":{{"Version":"{1}", "PluginURI":"{2}"}}}}}}"###, &*self.name, version, plugin_uri ), - "https://api.wordpress.org/plugins/update-check/1.1/" - ] - )); - Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###)) + "https://api.wordpress.org/plugins/update-check/1.1/", + ], + )?; + Ok(String::from_utf8(upstream)?.contains(r###""plugins":[]"###)) } fn execute(&self) -> Result<(), Box> { let source = format!("https://downloads.wordpress.org/plugin/{}.zip", &*self.name); let zip = format!("/tmp/{}.zip", &*self.name); - try!(self + self .command_runner - .run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()])); - try!(self + .run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()])?; + self .command_runner - .run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()])); + .run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()])?; self.command_runner.run_successfully( "unzip", &[ diff --git a/src/symbols/wordpress/translation.rs b/src/symbols/wordpress/translation.rs index a09a66e..dcf6f22 100644 --- a/src/symbols/wordpress/translation.rs +++ b/src/symbols/wordpress/translation.rs @@ -102,7 +102,7 @@ where if target.ends_with(".po") { let reader = BufReader::new(file); for content in reader.lines() { - if let Some(match_result) = match_date.captures(&try!(content)) { + if let Some(match_result) = match_date.captures(&content?) { newest = max(newest, match_result[1].to_string()); break; } @@ -111,15 +111,15 @@ where } } } - let upstream = try!(self.command_runner.get_output( + let upstream = self.command_runner.get_output( "curl", &[&format!( "https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale.as_ref() - )] - )); - Ok(try!(String::from_utf8(upstream)).contains(&format!( + )], + )?; + Ok(String::from_utf8(upstream)?.contains(&format!( r###"language":"{}","version":"{}","updated":"{}"###, self.locale.as_ref(), self.version, @@ -129,9 +129,9 @@ where fn execute(&self) -> Result<(), Box> { for (source, target) in self.get_pairs() { - try!(self + self .command_runner - .run_successfully("curl", &["--compressed", "-o", &target, &source])); + .run_successfully("curl", &["--compressed", "-o", &target, &source])?; } Ok(()) }