aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2021-03-27 04:13:39 +0000
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2021-03-27 04:13:39 +0000
commit0f276b6ec8383cea3f3da726682594e5e683033a (patch)
tree0d554bc521ce64d15a1c1bbd7fdb19210389ad19
parent(cargo-release) start next development iteration 0.12.2-alpha.0 (diff)
downloadminiserve-0f276b6ec8383cea3f3da726682594e5e683033a.tar.gz
miniserve-0f276b6ec8383cea3f3da726682594e5e683033a.zip
Resolve symlinks when listing
This has the benefit of showing the size and modification date of the pointed-to file. Symlink to directories now respects '--dirs-first' option and broken symlinks don't show in directory listing.
Diffstat (limited to '')
-rw-r--r--src/listing.rs22
-rw-r--r--src/renderer.rs4
2 files changed, 3 insertions, 23 deletions
diff --git a/src/listing.rs b/src/listing.rs
index 66aea6b..2fe583c 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -65,9 +65,6 @@ pub enum EntryType {
/// Entry is a file
File,
-
- /// Entry is a symlink
- Symlink,
}
/// Entry
@@ -114,11 +111,6 @@ impl Entry {
pub fn is_file(&self) -> bool {
self.entry_type == EntryType::File
}
-
- /// Returns wether the entry is a symlink
- pub fn is_symlink(&self) -> bool {
- self.entry_type == EntryType::Symlink
- }
}
/// One entry in the path to the listed directory
@@ -260,7 +252,7 @@ pub fn directory_listing(
let file_name = entry.file_name().to_string_lossy().to_string();
// if file is a directory, add '/' to the end of the name
- if let Ok(metadata) = entry.metadata() {
+ if let Ok(metadata) = std::fs::metadata(entry.path()) {
if skip_symlinks && metadata.file_type().is_symlink() {
continue;
}
@@ -269,15 +261,7 @@ pub fn directory_listing(
Err(_) => None,
};
- if metadata.file_type().is_symlink() {
- entries.push(Entry::new(
- file_name,
- EntryType::Symlink,
- file_url,
- None,
- last_modification_date,
- ));
- } else if metadata.is_dir() {
+ if metadata.is_dir() {
entries.push(Entry::new(
file_name,
EntryType::Directory,
@@ -285,7 +269,7 @@ pub fn directory_listing(
None,
last_modification_date,
));
- } else {
+ } else if metadata.is_file() {
entries.push(Entry::new(
file_name,
EntryType::File,
diff --git a/src/renderer.rs b/src/renderer.rs
index c9ec9cd..2487696 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -341,10 +341,6 @@ fn entry_row(
}
}
}
- } @else if entry.is_symlink() {
- a.symlink href=(parametrized_link(&entry.link, sort_method, sort_order)) {
- (entry.name) span.symlink-symbol { "⇢" }
- }
}
}
}