From 33c79837f1e113a1ce83a461413acf474e973c63 Mon Sep 17 00:00:00 2001 From: Alec Di Vito Date: Sun, 2 Mar 2025 14:46:10 -0500 Subject: feat: validate temp dir exists through `value_parser` and fixed clippy issues --- src/args.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index e9243f5..72ade7b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -36,6 +36,7 @@ pub struct CliArgs { long = "temp-directory", value_hint = ValueHint::FilePath, requires = "allowed_upload_dir", + value_parser(validate_is_dir_and_exists), env = "MINISERVER_TEMP_UPLOAD_DIRECTORY") ] pub temp_upload_directory: Option, @@ -356,6 +357,20 @@ fn parse_interface(src: &str) -> Result { src.parse::() } +/// Validate that a path passed in is a directory and it exists. +fn validate_is_dir_and_exists(s: &str) -> Result { + let path = PathBuf::from(s); + if path.exists() && path.is_dir() { + Ok(path) + } else { + Err(format!( + "Upload temporary directory must exist and be a directory. \ + Validate that path {:?} meets those requirements.", + path + )) + } +} + #[derive(Clone, Debug, thiserror::Error)] pub enum AuthParseError { /// Might occur if the HTTP credential string does not respect the expected format -- cgit v1.2.3