history file opens file or fails

This commit is contained in:
Paul Campbell 2023-08-04 19:43:50 +01:00
parent bf044bd7c8
commit a21f2e0719

View file

@ -5,14 +5,17 @@ use std::io::{BufRead, BufReader};
use super::Link; use super::Link;
pub fn find(link: &Link, file_name: &str, e: &FileEnv) -> Result<bool> { pub fn find(link: &Link, file_name: &str, e: &FileEnv) -> Result<bool> {
if let Ok(file) = (e.open)(file_name) { println!("Opening file: {file_name}");
let file = (e.open)(file_name)?;
println!("Opened file: {file_name}");
let reader = BufReader::new(file); let reader = BufReader::new(file);
for line in reader.lines() { for line in reader.lines() {
if line? == link.href { let line = line?;
if line == link.href {
println!("history: {}", line);
return Ok(true); // is already downloaded return Ok(true); // is already downloaded
} }
} }
}
Ok(false) // is not already downloaded Ok(false) // is not already downloaded
} }