aboutsummaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.rs')
-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