diff options
author | pebbleKite <pebbleKite@users.noreply.github.com> | 2018-11-08 12:54:04 +0000 |
---|---|---|
committer | pebbleKite <pebbleKite@users.noreply.github.com> | 2018-11-08 12:54:04 +0000 |
commit | 8034d4b2604dd3f5dc97c95e7da8e302e0044068 (patch) | |
tree | 13f5fd65b3738a35967f13197acc88cbc4ca73e2 /src | |
parent | add option to ignore symlinks (diff) | |
download | miniserve-8034d4b2604dd3f5dc97c95e7da8e302e0044068.tar.gz miniserve-8034d4b2604dd3f5dc97c95e7da8e302e0044068.zip |
Use same renderer when skipping symlinks and not
Diffstat (limited to '')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 9 insertions, 10 deletions
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<MiniserveConfig>) -> App<MiniserveConfig> { 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<S>( +fn directory_listing<S>( dir: &fs::Directory, req: &HttpRequest<S>, + skip_symlinks: bool, ) -> Result<HttpResponse, io::Error> { let index_of = format!("Index of {}", req.path()); let mut body = String::new(); @@ -381,7 +380,7 @@ fn no_symlink_directory_listing<S>( // 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() { |