From dc92b4e4107885b8a891ce3406e0fca236ccb2d5 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Fri, 19 Feb 2021 06:08:02 +0100 Subject: Fix lints --- src/archive.rs | 18 +++++++++--------- src/args.rs | 4 ++-- src/auth.rs | 4 ++-- src/errors.rs | 8 ++++---- src/file_upload.rs | 10 +++++----- src/main.rs | 12 ++++++------ 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 40a6250..894ee3f 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -90,13 +90,13 @@ fn tar_gz(dir: &Path, skip_symlinks: bool, out: W) -> Result<(), ContextualEr where W: std::io::Write, { - let mut out = Encoder::new(out).map_err(|e| ContextualError::IOError("GZIP".to_string(), e))?; + let mut out = Encoder::new(out).map_err(|e| ContextualError::IoError("GZIP".to_string(), e))?; tar_dir(dir, skip_symlinks, &mut out)?; out.finish() .into_result() - .map_err(|e| ContextualError::IOError("GZIP finish".to_string(), e))?; + .map_err(|e| ContextualError::IoError("GZIP finish".to_string(), e))?; Ok(()) } @@ -162,7 +162,7 @@ where tar_builder .append_dir_all(inner_folder, src_dir) .map_err(|e| { - ContextualError::IOError( + ContextualError::IoError( format!( "Failed to append the content of {} to the TAR archive", src_dir.to_str().unwrap_or("file") @@ -173,7 +173,7 @@ where // Finish the archive tar_builder.into_inner().map_err(|e| { - ContextualError::IOError("Failed to finish writing the TAR archive".to_string(), e) + ContextualError::IoError("Failed to finish writing the TAR archive".to_string(), e) })?; Ok(()) @@ -224,7 +224,7 @@ where })?; let current_dir = next.as_path(); let directory_entry_iterator = std::fs::read_dir(current_dir) - .map_err(|e| ContextualError::IOError("Could not read directory".to_string(), e))?; + .map_err(|e| ContextualError::IoError("Could not read directory".to_string(), e))?; let zip_directory = Path::new(zip_root_folder_name).join(current_dir.strip_prefix(directory).map_err( |_| ContextualError::CustomError("Could not append base directory".to_string()), @@ -240,7 +240,7 @@ where })? .path(); let entry_metadata = std::fs::metadata(entry_path.clone()).map_err(|e| { - ContextualError::IOError("Could not get file metadata".to_string(), e) + ContextualError::IoError("Could not get file metadata".to_string(), e) })?; if entry_metadata.file_type().is_symlink() && skip_symlinks { @@ -251,9 +251,9 @@ where })?; if entry_metadata.is_file() { let mut f = File::open(&entry_path) - .map_err(|e| ContextualError::IOError("Could not open file".to_string(), e))?; + .map_err(|e| ContextualError::IoError("Could not open file".to_string(), e))?; f.read_to_end(&mut buffer).map_err(|e| { - ContextualError::IOError("Could not read from file".to_string(), e) + ContextualError::IoError("Could not read from file".to_string(), e) })?; let relative_path = zip_directory.join(current_entry_name).into_os_string(); zip_writer @@ -302,7 +302,7 @@ where })?; out.write_all(data.as_mut_slice()) - .map_err(|e| ContextualError::IOError("Failed to write the ZIP archive".to_string(), e))?; + .map_err(|e| ContextualError::IoError("Failed to write the ZIP archive".to_string(), e))?; Ok(()) } diff --git a/src/args.rs b/src/args.rs index ad3f85c..f736941 100644 --- a/src/args.rs +++ b/src/args.rs @@ -19,7 +19,7 @@ const ROUTE_ALPHABET: [char; 16] = [ about, global_settings = &[structopt::clap::AppSettings::ColoredHelp], )] -struct CLIArgs { +struct CliArgs { /// Be verbose, includes emitting access logs #[structopt(short = "v", long = "verbose")] verbose: bool, @@ -172,7 +172,7 @@ fn parse_auth(src: &str) -> Result { /// Parses the command line arguments pub fn parse_args() -> crate::MiniserveConfig { - let args = CLIArgs::from_args(); + let args = CliArgs::from_args(); let interfaces = if !args.interfaces.is_empty() { args.interfaces diff --git a/src/auth.rs b/src/auth.rs index a2dfe60..9e296ec 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -86,7 +86,7 @@ pub async fn handle_auth(req: ServiceRequest, cred: BasicAuth) -> Result String { let state = req.app_data::().unwrap(); - let error = ContextualError::HTTPAuthenticationError(Box::new(error)); + let error = ContextualError::HttpAuthenticationError(Box::new(error)); if log_error_chain { errors::log_error_chain(error.to_string()); diff --git a/src/errors.rs b/src/errors.rs index cb6efa8..1330390 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -8,7 +8,7 @@ pub enum ContextualError { /// Any kind of IO errors #[fail(display = "{}\ncaused by: {}", _0, _1)] - IOError(String, std::io::Error), + IoError(String, std::io::Error), /// MultipartError, which might occur during file upload, when processing the multipart request fails #[fail(display = "Failed to process multipart request\ncaused by: {}", _0)] @@ -59,15 +59,15 @@ pub enum ContextualError { display = "An error occured during HTTP authentication\ncaused by: {}", _0 )] - HTTPAuthenticationError(Box), + HttpAuthenticationError(Box), /// This error might occur when the HTTP credentials are not correct #[fail(display = "Invalid credentials for HTTP authentication")] - InvalidHTTPCredentials, + InvalidHttpCredentials, /// This error might occur when an HTTP request is invalid #[fail(display = "Invalid HTTP request\ncaused by: {}", _0)] - InvalidHTTPRequestError(String), + InvalidHttpRequestError(String), /// This error might occur when trying to access a page that does not exist #[fail(display = "Route {} could not be found", _0)] diff --git a/src/file_upload.rs b/src/file_upload.rs index 14aadfc..2fe0961 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -28,7 +28,7 @@ fn save_file( let mut file = match std::fs::File::create(&file_path) { Ok(file) => file, Err(e) => { - return Box::pin(future::err(ContextualError::IOError( + return Box::pin(future::err(ContextualError::IoError( format!("Failed to create {}", file_path.display()), e, ))); @@ -42,7 +42,7 @@ fn save_file( .write_all(bytes.as_ref()) .map(|_| acc + bytes.len() as i64) .map_err(|e| { - ContextualError::IOError("Failed to write to file".to_string(), e) + ContextualError::IoError("Failed to write to file".to_string(), e) }); future::ready(rt) }), @@ -128,7 +128,7 @@ pub fn upload_file( Err(_) => path.clone(), }, None => { - let err = ContextualError::InvalidHTTPRequestError( + let err = ContextualError::InvalidHttpRequestError( "Missing query parameter 'path'".to_string(), ); return Box::pin(create_error_response( @@ -149,7 +149,7 @@ pub fn upload_file( let app_root_dir = match conf.path.canonicalize() { Ok(dir) => dir, Err(e) => { - let err = ContextualError::IOError( + let err = ContextualError::IoError( "Failed to resolve path served by miniserve".to_string(), e, ); @@ -172,7 +172,7 @@ pub fn upload_file( let target_dir = match &app_root_dir.join(upload_path).canonicalize() { Ok(path) if path.starts_with(&app_root_dir) => path.clone(), _ => { - let err = ContextualError::InvalidHTTPRequestError( + let err = ContextualError::InvalidHttpRequestError( "Invalid value for 'path' parameter".to_string(), ); return Box::pin(create_error_response( diff --git a/src/main.rs b/src/main.rs index 136b986..c55e77f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,7 @@ async fn run() -> Result<(), ContextualError> { .path .symlink_metadata() .map_err(|e| { - ContextualError::IOError("Failed to retrieve symlink's metadata".to_string(), e) + ContextualError::IoError("Failed to retrieve symlink's metadata".to_string(), e) })? .file_type() .is_symlink(); @@ -159,7 +159,7 @@ async fn run() -> Result<(), ContextualError> { .collect::>(); let canon_path = miniserve_config.path.canonicalize().map_err(|e| { - ContextualError::IOError("Failed to resolve path to be served".to_string(), e) + ContextualError::IoError("Failed to resolve path to be served".to_string(), e) })?; if let Some(index_path) = &miniserve_config.index { @@ -186,12 +186,12 @@ async fn run() -> Result<(), ContextualError> { print!("Starting server in "); io::stdout() .flush() - .map_err(|e| ContextualError::IOError("Failed to write data".to_string(), e))?; + .map_err(|e| ContextualError::IoError("Failed to write data".to_string(), e))?; for c in "3… 2… 1… \n".chars() { print!("{}", c); io::stdout() .flush() - .map_err(|e| ContextualError::IOError("Failed to write data".to_string(), e))?; + .map_err(|e| ContextualError::IoError("Failed to write data".to_string(), e))?; thread::sleep(Duration::from_millis(500)); } } @@ -263,7 +263,7 @@ async fn run() -> Result<(), ContextualError> { .default_service(web::get().to(error_404)) }) .bind(socket_addresses.as_slice()) - .map_err(|e| ContextualError::IOError("Failed to bind server".to_string(), e))? + .map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))? .shutdown_timeout(0) .run(); @@ -276,7 +276,7 @@ async fn run() -> Result<(), ContextualError> { println!("\nQuit by pressing CTRL-C"); srv.await - .map_err(|e| ContextualError::IOError("".to_owned(), e)) + .map_err(|e| ContextualError::IoError("".to_owned(), e)) } /// Configures the Actix application -- cgit v1.2.3