format tweaks

pull/1/head
chris west 4 years ago
parent 49ae7abb63
commit 2714841316

@ -35,12 +35,11 @@ impl Request {
/// Path to the target file on disk requested by this request. /// Path to the target file on disk requested by this request.
pub fn file_path(&self) -> String { pub fn file_path(&self) -> String {
let mut path = self.root.to_string(); format!(
if !path.ends_with('/') { "{}/{}",
path.push('/'); self.root.to_string().trim_end_matches('/'),
} self.selector.replace("..", ".").trim_start_matches('/')
path.push_str(self.selector.replace("..", ".").trim_start_matches('/')); )
path
} }
/// Path to the target file relative to the server root. /// Path to the target file relative to the server root.

@ -148,8 +148,7 @@ where
let rel_path = req.relative_file_path(); let rel_path = req.relative_file_path();
// show directory entries // show directory entries
let mut reverse = path.to_string(); let reverse = format!("{}/.reverse", path);
reverse.push_str("/.reverse");
let paths = sort_paths(&path, fs_exists(&reverse))?; let paths = sort_paths(&path, fs_exists(&reverse))?;
for entry in paths { for entry in paths {
let file_name = entry.file_name(); let file_name = entry.file_name();
@ -157,11 +156,11 @@ where
if f.chars().nth(0) == Some('.') || IGNORED_FILES.contains(&f.as_ref()) { if f.chars().nth(0) == Some('.') || IGNORED_FILES.contains(&f.as_ref()) {
continue; continue;
} }
let mut path = rel_path.clone(); let path = format!(
if path != "/" { "{}/{}",
path.push('/'); rel_path.trim_end_matches('/'),
} file_name.to_string_lossy()
path.push_str(&file_name.to_string_lossy()); );
menu.write_entry( menu.write_entry(
file_type(&entry), file_type(&entry),
&file_name.to_string_lossy(), &file_name.to_string_lossy(),
@ -171,11 +170,9 @@ where
)?; )?;
} }
let mut footer = path; let footer = format!("{}/footer.gph", path.trim_end_matches('/'));
footer.push_str("/footer.gph");
if fs_exists(&footer) { if fs_exists(&footer) {
let mut sel = req.selector.clone(); let sel = format!("{}/footer.gph", req.selector);
sel.push_str("/footer.gph");
write_gophermap( write_gophermap(
w, w,
Request { Request {

Loading…
Cancel
Save