From d1d06514a9b73015029315c01c43a6c34f43079a Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 19 Aug 2024 17:52:16 +0200 Subject: [PATCH] cargo fmt + clippy --- src/cli/mysql_admutils_compatibility/mysql_dbadm.rs | 10 +++++----- src/cli/mysql_admutils_compatibility/mysql_useradm.rs | 10 +++++----- src/core/bootstrap.rs | 3 +++ src/main.rs | 10 +++++----- src/server/common.rs | 2 +- src/server/config.rs | 7 ++++--- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/cli/mysql_admutils_compatibility/mysql_dbadm.rs b/src/cli/mysql_admutils_compatibility/mysql_dbadm.rs index 0b4518e..0e881c1 100644 --- a/src/cli/mysql_admutils_compatibility/mysql_dbadm.rs +++ b/src/cli/mysql_admutils_compatibility/mysql_dbadm.rs @@ -56,11 +56,11 @@ The Y/N-values corresponds to the following mysql privileges: /// Please consider using the newer mysqladm command instead. #[derive(Parser)] #[command( - bin_name = "mysql-dbadm", - version, - about, - disable_help_subcommand = true, - verbatim_doc_comment, + bin_name = "mysql-dbadm", + version, + about, + disable_help_subcommand = true, + verbatim_doc_comment )] pub struct Args { #[command(subcommand)] diff --git a/src/cli/mysql_admutils_compatibility/mysql_useradm.rs b/src/cli/mysql_admutils_compatibility/mysql_useradm.rs index 5de17f0..cdc7254 100644 --- a/src/cli/mysql_admutils_compatibility/mysql_useradm.rs +++ b/src/cli/mysql_admutils_compatibility/mysql_useradm.rs @@ -32,11 +32,11 @@ use crate::{ /// Please consider using the newer mysqladm command instead. #[derive(Parser)] #[command( - bin_name = "mysql-useradm", - version, - about, - disable_help_subcommand = true, - verbatim_doc_comment, + bin_name = "mysql-useradm", + version, + about, + disable_help_subcommand = true, + verbatim_doc_comment )] pub struct Args { #[command(subcommand)] diff --git a/src/core/bootstrap.rs b/src/core/bootstrap.rs index 891b52a..1d3c06f 100644 --- a/src/core/bootstrap.rs +++ b/src/core/bootstrap.rs @@ -32,15 +32,18 @@ pub fn drop_privs() -> anyhow::Result<()> { /// This function is used to bootstrap the connection to the server. /// This can happen in two ways: +/// /// 1. If a socket path is provided, or exists in the default location, /// the function will connect to the socket and authenticate with the /// server to ensure that the server knows the uid of the client. +/// /// 2. If a config path is provided, or exists in the default location, /// and the config is readable, the function will assume it is either /// setuid or setgid, and will fork a child process to run the server /// with the provided config. The server will exit silently by itself /// when it is done, and this function will only return for the client /// with the socket for the server. +/// /// If neither of these options are available, the function will fail. pub fn bootstrap_server_connection_and_drop_privileges( server_socket_path: Option, diff --git a/src/main.rs b/src/main.rs index d0ac70b..549072f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,17 +109,17 @@ fn main() -> anyhow::Result<()> { env_logger::init(); #[cfg(feature = "mysql-admutils-compatibility")] - if let Some(_) = handle_mysql_admutils_command()? { + if handle_mysql_admutils_command()?.is_some() { return Ok(()); } let args: Args = Args::parse(); - if let Some(_) = handle_server_command(&args)? { + if handle_server_command(&args)?.is_some() { return Ok(()); } - if let Some(_) = handle_generate_completions_command(&args)? { + if handle_generate_completions_command(&args)?.is_some() { return Ok(()); } @@ -139,8 +139,8 @@ fn handle_mysql_admutils_command() -> anyhow::Result> { }); match argv0.as_deref() { - Some("mysql-dbadm") => mysql_dbadm::main().map(|result| Some(result)), - Some("mysql-useradm") => mysql_useradm::main().map(|result| Some(result)), + Some("mysql-dbadm") => mysql_dbadm::main().map(Some), + Some("mysql-useradm") => mysql_useradm::main().map(Some), _ => Ok(None), } } diff --git a/src/server/common.rs b/src/server/common.rs index fb39122..c42187a 100644 --- a/src/server/common.rs +++ b/src/server/common.rs @@ -23,4 +23,4 @@ pub fn try_get_with_binary_fallback( row.try_get::, _>(column) .map(|v| String::from_utf8_lossy(&v).to_string()) }) -} \ No newline at end of file +} diff --git a/src/server/config.rs b/src/server/config.rs index 4989c07..3010e43 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -141,8 +141,7 @@ pub async fn create_mysql_connection_from_config( ) -> anyhow::Result { log_config(config); - let mut mysql_options = MySqlConnectOptions::new() - .database("mysql"); + let mut mysql_options = MySqlConnectOptions::new().database("mysql"); if let Some(username) = &config.username { mysql_options = mysql_options.username(username); @@ -168,6 +167,8 @@ pub async fn create_mysql_connection_from_config( .await { Ok(connection) => connection.context("Failed to connect to the database"), - Err(_) => Err(anyhow!("Timed out after 2 seconds")).context("Failed to connect to the database"), + Err(_) => { + Err(anyhow!("Timed out after 2 seconds")).context("Failed to connect to the database") + } } }