From 35ed4394df5673e537c8b59d8563d59e34afbf4c Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 1 Jun 2022 19:59:35 +0800 Subject: [PATCH] fix: caught 500 if no permission to access dir releated #4 --- src/server.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/server.rs b/src/server.rs index f6f6a02..90faa4d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -241,7 +241,13 @@ impl InnerService { async fn handle_ls_dir(&self, path: &Path, exist: bool, res: &mut Response) -> BoxResult<()> { let mut paths: Vec = vec![]; if exist { - let mut rd = fs::read_dir(path).await?; + let mut rd = match fs::read_dir(path).await { + Ok(rd) => rd, + Err(_) => { + status!(res, StatusCode::FORBIDDEN); + return Ok(()); + } + }; while let Some(entry) = rd.next_entry().await? { let entry_path = entry.path(); if let Ok(Some(item)) = self.to_pathitem(entry_path, path.to_path_buf()).await {