2
0
mirror of https://github.com/xvxx/phd synced 2024-11-10 13:10:23 +00:00

dont ensure

This commit is contained in:
dvkt 2019-12-27 22:00:43 -08:00
parent f0457bfccc
commit 1465c5beed

View File

@ -69,11 +69,9 @@ where
} else { } else {
// check for index.gph if we're looking for dir // check for index.gph if we're looking for dir
let mut index = path.clone(); let mut index = path.clone();
ensure_trailing_slash(&mut index); index.push_str("/index.gph");
index.push_str("index.gph");
if Path::new(&index).exists() { if Path::new(&index).exists() {
ensure_trailing_slash(&mut req.selector); req.selector.push_str("/index.gph");
req.selector.push_str("index.gph");
return write_gophermap(w, req); return write_gophermap(w, req);
} }
} }
@ -137,7 +135,7 @@ where
continue; continue;
} }
let mut path = rel_path.clone(); let mut path = rel_path.clone();
ensure_trailing_slash(&mut path); path.push('/');
path.push_str(&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),
@ -175,9 +173,7 @@ where
&'a W: Write, &'a W: Write,
{ {
let path = req.file_path(); let path = req.file_path();
println!("write_gophermap: {:?}", path);
let file = File::open(&path)?; let file = File::open(&path)?;
println!("write_gophermap: {:?}", path);
let reader = BufReader::new(file); let reader = BufReader::new(file);
for line in reader.lines() { for line in reader.lines() {
let mut line = line?.trim_end_matches("\r\n").to_string(); let mut line = line?.trim_end_matches("\r\n").to_string();
@ -223,9 +219,3 @@ fn file_type(dir: &fs::DirEntry) -> ItemType {
ItemType::Error ItemType::Error
} }
} }
fn ensure_trailing_slash(s: &mut String) {
if !s.ends_with('/') {
s.push('/');
}
}