From 9ce64f88fac864f7b083bf61f7d8797f34655548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sun, 20 Sep 2020 18:58:53 +0200 Subject: [PATCH] test for directory name + .tar, not just directory name --- src/web.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/web.rs b/src/web.rs index 8f3336c..fa3630c 100644 --- a/src/web.rs +++ b/src/web.rs @@ -32,11 +32,16 @@ pub async fn run(bind_addr: &str, root: &PathBuf) -> std::io::Result<()> { #[get("/{tail:.*}.tar")] async fn handle_tar(req: HttpRequest, root: web::Data, web::Path(tail): web::Path) -> impl Responder { let relpath = PathBuf::from(tail.trim_end_matches('/')); - let fullpath = root.join(&relpath).canonicalize() - .map_err(|err| error::InternalError::new(err, StatusCode::INTERNAL_SERVER_ERROR))?; + let fullpath = root.join(&relpath) + .canonicalize() + .map_err(|err| error::InternalError::new(err, StatusCode::NOT_FOUND))?; - if fullpath.is_file() { - return NamedFile::open(fullpath) + + // if a .tar already exists, just return it as-is + let mut fullpath_tar = fullpath.clone(); + fullpath_tar.set_extension("tar"); + if fullpath_tar.is_file() { + return NamedFile::open(fullpath_tar) .map_err(|err| error::InternalError::new(err, StatusCode::INTERNAL_SERVER_ERROR))? .into_response(&req); }