Skip to content

Commit

Permalink
format tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
xvxx committed May 9, 2020
1 parent 49ae7ab commit 2714841
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
11 changes: 5 additions & 6 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ impl Request {

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

/// Path to the target file relative to the server root.
Expand Down
19 changes: 8 additions & 11 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,19 @@ where
let rel_path = req.relative_file_path();

// show directory entries
let mut reverse = path.to_string();
reverse.push_str("/.reverse");
let reverse = format!("{}/.reverse", path);
let paths = sort_paths(&path, fs_exists(&reverse))?;
for entry in paths {
let file_name = entry.file_name();
let f = file_name.to_string_lossy().to_string();
if f.chars().nth(0) == Some('.') || IGNORED_FILES.contains(&f.as_ref()) {
continue;
}
let mut path = rel_path.clone();
if path != "/" {
path.push('/');
}
path.push_str(&file_name.to_string_lossy());
let path = format!(
"{}/{}",
rel_path.trim_end_matches('/'),
file_name.to_string_lossy()
);
menu.write_entry(
file_type(&entry),
&file_name.to_string_lossy(),
Expand All @@ -171,11 +170,9 @@ where
)?;
}

let mut footer = path;
footer.push_str("/footer.gph");
let footer = format!("{}/footer.gph", path.trim_end_matches('/'));
if fs_exists(&footer) {
let mut sel = req.selector.clone();
sel.push_str("/footer.gph");
let sel = format!("{}/footer.gph", req.selector);
write_gophermap(
w,
Request {
Expand Down

0 comments on commit 2714841

Please sign in to comment.