From d112312c3fcf79c679e2aa4a47a60b69f83cbce9 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sat, 24 May 2025 18:12:43 +0200 Subject: remove already assigned filepaths from pdf_files vec --- src/bibiman/bibisetup.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index b968658..aa0640c 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -189,7 +189,7 @@ impl BibiSetup { bibliography: &Bibliography, cfg: &BibiConfig, ) -> Vec { - let pdf_files = if cfg.general.pdf_path.is_some() { + let mut pdf_files = if cfg.general.pdf_path.is_some() { collect_pdf_files(cfg.general.pdf_path.as_ref().unwrap()) } else { None @@ -208,7 +208,7 @@ impl BibiSetup { citekey: k.to_owned(), abstract_text: Self::get_abstract(k, bibliography), doi_url: Self::get_weblink(k, bibliography), - filepath: Self::get_filepath(k, bibliography, &pdf_files), + filepath: Self::get_filepath(k, bibliography, &mut pdf_files), subtitle: Self::get_subtitle(k, bibliography), }) .collect() @@ -343,7 +343,7 @@ impl BibiSetup { pub fn get_filepath( citekey: &str, biblio: &Bibliography, - pdf_files: &Option>, + pdf_files: &mut Option>, ) -> Option { if biblio.get(citekey).unwrap().file().is_ok() { Some(biblio.get(citekey).unwrap().file().unwrap().trim().into()) @@ -369,7 +369,10 @@ impl BibiSetup { } } - fn merge_filepath_or_none(citekey: &str, pdf_files: &Option>) -> Option { + fn merge_filepath_or_none( + citekey: &str, + pdf_files: &mut Option>, + ) -> Option { // Oder n Loop??? let pdf_file = { let mut idx = 0; @@ -395,7 +398,9 @@ impl BibiSetup { .unwrap() == citekey { - break Some(cur_entry.to_owned().into_os_string()); + let path = cur_entry.to_owned().into_os_string(); + pdf_files.as_mut().unwrap().swap_remove(idx); + break Some(path); } else { idx += 1 } -- cgit v1.2.3