diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2019-05-10 18:17:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 18:17:55 +0000 |
commit | 1b92ddb24ec9d364d8170912e047317eef726c7d (patch) | |
tree | c2ccd3786cb68b123bf90190b9d9c47ec34b9559 | |
parent | Merge pull request #90 from boastful-squirrel/themed-errors (diff) | |
parent | Fix clippy (diff) | |
download | miniserve-1b92ddb24ec9d364d8170912e047317eef726c7d.tar.gz miniserve-1b92ddb24ec9d364d8170912e047317eef726c7d.zip |
Merge pull request #112 from boastful-squirrel/fix-clippy
Fix Clippy warnings + cargo fmt
-rw-r--r-- | src/archive.rs | 43 | ||||
-rw-r--r-- | src/args.rs | 8 | ||||
-rw-r--r-- | src/errors.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/renderer.rs | 1 | ||||
-rw-r--r-- | tests/auth.rs | 2 |
6 files changed, 22 insertions, 41 deletions
diff --git a/src/archive.rs b/src/archive.rs index a76446a..02300c5 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; use strum_macros::{Display, EnumIter, EnumString}; use tar::Builder; -use crate::errors::{ContextualError}; +use crate::errors::ContextualError; /// Available compression methods #[derive(Deserialize, Clone, EnumIter, EnumString, Display)] @@ -62,17 +62,11 @@ fn tgz_compress(dir: &PathBuf, skip_symlinks: bool) -> Result<(String, Bytes), C let mut tgz_data = Bytes::new(); let tar_data = tar(src_dir, directory.to_string(), skip_symlinks).map_err(|e| { - ContextualError::ArchiveCreationError( - "tarball".to_string(), - Box::new(e), - ) + ContextualError::ArchiveCreationError("tarball".to_string(), Box::new(e)) })?; let gz_data = gzip(&tar_data).map_err(|e| { - ContextualError::ArchiveCreationError( - "GZIP archive".to_string(), - Box::new(e), - ) + ContextualError::ArchiveCreationError("GZIP archive".to_string(), Box::new(e)) })?; tgz_data.extend_from_slice(&gz_data); @@ -115,10 +109,7 @@ fn tar( })?; let tar_content = 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(tar_content) @@ -126,24 +117,14 @@ fn tar( /// Compresses a stream of bytes using the GZIP algorithm, and returns the resulting stream fn gzip(mut data: &[u8]) -> Result<Vec<u8>, ContextualError> { - let mut encoder = Encoder::new(Vec::new()).map_err(|e| { - ContextualError::IOError( - "Failed to create GZIP encoder".to_string(), - e, - ) - })?; - io::copy(&mut data, &mut encoder).map_err(|e| { - ContextualError::IOError( - "Failed to write GZIP data".to_string(), - e, - ) - })?; - let data = encoder.finish().into_result().map_err(|e| { - ContextualError::IOError( - "Failed to write GZIP trailer".to_string(), - e, - ) - })?; + let mut encoder = Encoder::new(Vec::new()) + .map_err(|e| ContextualError::IOError("Failed to create GZIP encoder".to_string(), e))?; + io::copy(&mut data, &mut encoder) + .map_err(|e| ContextualError::IOError("Failed to write GZIP data".to_string(), e))?; + let data = encoder + .finish() + .into_result() + .map_err(|e| ContextualError::IOError("Failed to write GZIP trailer".to_string(), e))?; Ok(data) } diff --git a/src/args.rs b/src/args.rs index d291bb9..ea0a4ac 100644 --- a/src/args.rs +++ b/src/args.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use structopt::StructOpt; use crate::auth; -use crate::errors::{ContextualError}; +use crate::errors::ContextualError; use crate::themes; /// Possible characters for random routes @@ -99,15 +99,13 @@ fn parse_auth(src: &str) -> Result<auth::RequiredAuth, ContextualError> { let hash_bin = if let Ok(hash_bin) = hex::decode(hash_hex) { hash_bin } else { - return Err(ContextualError::InvalidPasswordHash) + return Err(ContextualError::InvalidPasswordHash); }; match second_part { "sha256" => auth::RequiredAuthPassword::Sha256(hash_bin.to_owned()), "sha512" => auth::RequiredAuthPassword::Sha512(hash_bin.to_owned()), - _ => { - return Err(ContextualError::InvalidHashMethod(second_part.to_owned())) - }, + _ => return Err(ContextualError::InvalidHashMethod(second_part.to_owned())), } } else { // To make it Windows-compatible, the password needs to be shorter than 255 characters. diff --git a/src/errors.rs b/src/errors.rs index 68f6d7d..2878e37 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -32,7 +32,10 @@ pub enum ContextualError { InvalidAuthFormat, /// This error might occure if the hash method is neither sha256 nor sha512 - #[fail(display = "{} is not a valid hashing method. Expected sha256 or sha512", _0)] + #[fail( + display = "{} is not a valid hashing method. Expected sha256 or sha512", + _0 + )] InvalidHashMethod(String), /// This error might occur if the HTTP auth hash password is not a valid hex code diff --git a/src/main.rs b/src/main.rs index bcfda09..bb61edc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,9 +83,7 @@ fn run() -> Result<(), ContextualError> { && miniserve_config .path .symlink_metadata() - .map_err(|e| { - ContextualError::IOError("Failed to retrieve symlink's metadata".to_string(), e) - })? + .map_err(|e| ContextualError::IOError("Failed to retrieve symlink's metadata".to_string(), e))? .file_type() .is_symlink() { diff --git a/src/renderer.rs b/src/renderer.rs index 098cf91..d1e16ea 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -846,6 +846,7 @@ fn humanize_systemtime(src_time: Option<SystemTime>) -> Option<String> { } /// Renders an error on the webpage +#[allow(clippy::too_many_arguments)] pub fn render_error( error_description: &str, error_code: StatusCode, diff --git a/tests/auth.rs b/tests/auth.rs index 0e5f9b7..128047d 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -3,13 +3,13 @@ mod fixtures; use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; use fixtures::{port, tmpdir, Error, FILES}; +use reqwest::StatusCode; use rstest::rstest_parametrize; use select::document::Document; use select::predicate::Text; use std::process::{Command, Stdio}; use std::thread::sleep; use std::time::Duration; -use reqwest::StatusCode; #[rstest_parametrize( cli_auth_arg, client_username, client_password, |