From 8034d4b2604dd3f5dc97c95e7da8e302e0044068 Mon Sep 17 00:00:00 2001 From: pebbleKite Date: Thu, 8 Nov 2018 14:54:04 +0200 Subject: Use same renderer when skipping symlinks and not --- src/main.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 127d364..688958c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -189,15 +189,13 @@ fn configure_app(app: App) -> App { if path.is_file() { None } else { - let res = fs::StaticFiles::new(path) - .expect("Couldn't create path") - .show_files_listing(); Some( - if no_symlinks { - res.files_listing_renderer(no_symlink_directory_listing) - } else { - res - } + fs::StaticFiles::new(path) + .expect("Couldn't create path") + .show_files_listing() + .files_listing_renderer(move |dir, req| { + directory_listing(dir, req, no_symlinks) + }), ) } }; @@ -358,9 +356,10 @@ fn main() { } // ↓ Adapted from https://docs.rs/actix-web/0.7.13/src/actix_web/fs.rs.html#564 -fn no_symlink_directory_listing( +fn directory_listing( dir: &fs::Directory, req: &HttpRequest, + skip_symlinks: bool, ) -> Result { let index_of = format!("Index of {}", req.path()); let mut body = String::new(); @@ -381,7 +380,7 @@ fn no_symlink_directory_listing( // if file is a directory, add '/' to the end of the name if let Ok(metadata) = entry.metadata() { - if metadata.file_type().is_symlink() { + if skip_symlinks && metadata.file_type().is_symlink() { continue; } if metadata.is_dir() { -- cgit v1.2.3