aboutsummaryrefslogtreecommitdiffstats
path: root/src/listing.rs
diff options
context:
space:
mode:
authorDean Li <deantvv@gmail.com>2021-06-03 13:26:27 +0000
committerDean Li <deantvv@gmail.com>2021-08-30 11:55:58 +0000
commit7944db336ca3ef0338369091af60aa2b15789952 (patch)
tree98d5c2a9e9a007a569710d60328e32713d832b60 /src/listing.rs
parentAdd CHANGELOG entry for binding behavior revamp (diff)
downloadminiserve-7944db336ca3ef0338369091af60aa2b15789952.tar.gz
miniserve-7944db336ca3ef0338369091af60aa2b15789952.zip
Implement show symlink destination
Add option `show_symlink_info` to represent show symlink info or not. (Default to no) Show symlink destination after symlink symbol in directory listing Resemble `ls -l` and also the short argument select for this feature is also `-l`. Basic testing is included. Related to #499
Diffstat (limited to 'src/listing.rs')
-rw-r--r--src/listing.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/listing.rs b/src/listing.rs
index 33a0342..8147113 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -84,9 +84,6 @@ pub struct Entry {
/// Type of the entry
pub entry_type: EntryType,
- /// Entry is symlink. Not mutually exclusive with entry_type
- pub is_symlink: bool,
-
/// URL of the entry
pub link: String,
@@ -95,24 +92,27 @@ pub struct Entry {
/// Last modification date
pub last_modification_date: Option<SystemTime>,
+
+ /// Path of symlink pointed to
+ pub symlink_info: Option<String>,
}
impl Entry {
fn new(
name: String,
entry_type: EntryType,
- is_symlink: bool,
link: String,
size: Option<bytesize::ByteSize>,
last_modification_date: Option<SystemTime>,
+ symlink_info: Option<String>,
) -> Self {
Entry {
name,
entry_type,
- is_symlink,
link,
size,
last_modification_date,
+ symlink_info,
}
}
@@ -168,6 +168,7 @@ pub fn directory_listing(
zip_enabled: bool,
dirs_first: bool,
hide_version_footer: bool,
+ show_symlink_info: bool,
title: Option<String>,
) -> io::Result<ServiceResponse> {
use actix_web::dev::BodyEncoding;
@@ -252,6 +253,11 @@ pub fn directory_listing(
}
res => (false, res),
};
+ let symlink_dest = if is_symlink && show_symlink_info {
+ Some(std::fs::read_link(entry.path())?)
+ } else {
+ None
+ };
let file_url = base
.join(&utf8_percent_encode(&file_name, PATH_SEGMENT).to_string())
.to_string_lossy()
@@ -271,19 +277,19 @@ pub fn directory_listing(
entries.push(Entry::new(
file_name,
EntryType::Directory,
- is_symlink,
file_url,
None,
last_modification_date,
+ symlink_dest.and_then(|s| s.into_os_string().into_string().ok()),
));
} else if metadata.is_file() {
entries.push(Entry::new(
file_name,
EntryType::File,
- is_symlink,
file_url,
Some(ByteSize::b(metadata.len())),
last_modification_date,
+ symlink_dest.and_then(|s| s.into_os_string().into_string().ok()),
));
}
} else {