1
0
Fork 0
mirror of https://github.com/icewind1991/zox synced 2026-06-03 18:34:07 +02:00

handle missing .z

This commit is contained in:
Robin Appelman 2020-03-03 22:44:52 +01:00
commit 73c7464c26

View file

@ -91,22 +91,20 @@ fn main() -> Result<(), MainError> {
let home = home::home_dir().expect("Cant get home directory"); let home = home::home_dir().expect("Cant get home directory");
let history_path = home.join(".z"); let history_path = home.join(".z");
let mut reader = csv::ReaderBuilder::new() let history_result = csv::ReaderBuilder::new()
.delimiter(b'|') .delimiter(b'|')
.has_headers(false) .has_headers(false)
.from_path(history_path.clone()) .from_path(history_path.clone())
.unwrap(); .map(|reader| reader.into_deserialize::<History>().filter_map(Result::ok));
let now = now(); let now = now();
let history = reader
.deserialize::<History>()
.filter_map(|result| result.ok());
if args.add { if args.add {
let home = home.to_str().expect("Home path not valid utf8").to_string(); let home = home.to_str().expect("Home path not valid utf8").to_string();
let mut history: Vec<_> = history.collect(); let mut history: Vec<_> = history_result
.map(|history| history.collect())
.unwrap_or_default();
for path in args.filter { for path in args.filter {
if path != home { if path != home {
@ -152,6 +150,7 @@ fn main() -> Result<(), MainError> {
return Ok(()); return Ok(());
} }
if let Ok(history) = history_result {
let matches = history.filter(|item| item.matches(&args.filter)); let matches = history.filter(|item| item.matches(&args.filter));
if args.list { if args.list {
@ -172,6 +171,7 @@ fn main() -> Result<(), MainError> {
println!("{}", first.path); println!("{}", first.path);
} }
} }
}
Ok(()) Ok(())
} }