Skip to content

Commit 6bfc5a7

Browse files
authored
Add path validation (#223)
1 parent 697a31b commit 6bfc5a7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server/src/option.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ pub struct Server {
199199
long,
200200
env = "P_STAGING_DIR",
201201
default_value = "./data",
202-
value_name = "path"
202+
value_name = "path",
203+
value_parser = validation::absolute_path
203204
)]
204205
pub local_staging_path: PathBuf,
205206

@@ -260,4 +261,11 @@ pub(self) mod validation {
260261

261262
Ok(path)
262263
}
264+
265+
pub fn absolute_path(s: &str) -> Result<PathBuf, String> {
266+
std::fs::canonicalize(s).map_err(|_| {
267+
"Could not construct absolute path from given path value for staging directory"
268+
.to_string()
269+
})
270+
}
263271
}

0 commit comments

Comments
 (0)