aboutsummaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorAlec Di Vito <me@alecdivito.com>2025-03-02 19:46:10 +0000
committerAlec Di Vito <me@alecdivito.com>2025-03-02 19:46:10 +0000
commit33c79837f1e113a1ce83a461413acf474e973c63 (patch)
treef1745dccd93f05fbb8a9920233ddef33bfe8963f /src/args.rs
parentfeat: address comments; add in new argument (`temp-directory`); add comments ... (diff)
downloadminiserve-33c79837f1e113a1ce83a461413acf474e973c63.tar.gz
miniserve-33c79837f1e113a1ce83a461413acf474e973c63.zip
feat: validate temp dir exists through `value_parser` and fixed clippy issues
Diffstat (limited to '')
-rw-r--r--src/args.rs15
1 files changed, 15 insertions, 0 deletions
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<PathBuf>,
@@ -356,6 +357,20 @@ fn parse_interface(src: &str) -> Result<IpAddr, std::net::AddrParseError> {
src.parse::<IpAddr>()
}
+/// Validate that a path passed in is a directory and it exists.
+fn validate_is_dir_and_exists(s: &str) -> Result<PathBuf, String> {
+ 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