crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

commit d17486a5e404bea07bc8a31a144e14ee10de8229
parent 4a0b7afdd2651c0a8dbed741ac3558de0f0aad05
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu, 16 Dec 2021 21:28:25 -0800

Remove files

Diffstat:
Msrc/main.rs | 29++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -15,7 +15,7 @@ use sha3::{ digest::{ExtendableOutput, Update, XofReader}, Shake128, }; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::fs::File; use std::io::prelude::*; use urlencoding; @@ -367,6 +367,8 @@ fn main() -> Result<()> { .collect(); std::fs::create_dir(&out_dir).ok(); let mut threads = vec![]; + let mut curr_threads = get_current_threads(&out_dir); + for root in &mut thread_roots { let mut thread_ids = vec![]; let mut current: Vec<String> = vec![root.id.clone()]; @@ -396,9 +398,17 @@ fn main() -> Result<()> { thread.last_reply = thread.last_reply(); thread.write_to_file(&out_dir)?; + curr_threads.remove(&thread.hash); threads.push(thread); } + for leftover in curr_threads { + let file_to_remove = out_dir.join("threads").join(format!("{}.html", leftover)); + std::fs::remove_file(&file_to_remove)?; + } + + // Remove any threads left over + threads.sort_by_key(|a| a.last_reply); threads.reverse(); ThreadList { threads }.write_to_file(&out_dir)?; @@ -412,8 +422,21 @@ fn main() -> Result<()> { } // Use the sha3 hash of the ID. It is what it is. -fn get_current_messages() { - let paths = std::fs::read_dir("./").unwrap(); +// lots of unwrapping here +fn get_current_threads(out_dir: &Path) -> HashSet<String> { + std::fs::read_dir(out_dir.join("threads")) + .unwrap() + .map(|x| { + x.unwrap() + .path() + .file_stem() + .unwrap() + .to_str() + .unwrap() + .to_owned() + }) + .filter(|x| !(x == "style")) + .collect() } fn parse_path(s: &std::ffi::OsStr) -> Result<std::path::PathBuf, &'static str> {