Skip to content

Commit

Permalink
Fix static dir set dot files not working
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Nov 24, 2023
1 parent d23fc50 commit 62bff47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/serve-static/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,14 @@ impl Handler for StaticDir {
// list the dir
if let Ok(mut entries) = tokio::fs::read_dir(&abs_path).await {
while let Ok(Some(entry)) = entries.next_entry().await {
if let Ok(metadata) = entry.metadata().await {
if metadata.is_dir() {
dirs.entry(entry.file_name().to_string_lossy().to_string())
.or_insert(metadata);
} else {
let file_name = entry.file_name().to_string_lossy().to_string();
if !self.dot_files && file_name.starts_with('.') {
continue;
let file_name = entry.file_name().to_string_lossy().to_string();
if self.dot_files || (!self.dot_files && !file_name.starts_with('.')) {
if let Ok(metadata) = entry.metadata().await {
if metadata.is_dir() {
dirs.entry(file_name).or_insert(metadata);
} else {
files.entry(file_name).or_insert(metadata);
}
files.entry(file_name).or_insert(metadata);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/static-dir-list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async fn main() {
"static/boy",
"static/girl",
])
.dot_files(true)
.defaults("index.html")
.listing(true),
);
Expand Down
5 changes: 5 additions & 0 deletions examples/static-dir-list/static/boy/.dot/dotfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dot file

An elephant said to a mouse ,"no doubt that you are the smallest znd most useless thing that Ihave e ver seen ."

"Pless ,say it again .Let me take it down ."the mouse said ."I will tell a flea what I know.

0 comments on commit 62bff47

Please sign in to comment.