Filter out missing media-paths at write time

This commit is contained in:
RumovZ 2022-03-28 12:42:02 +02:00
parent 566973146f
commit 6269a88cd3
2 changed files with 6 additions and 10 deletions

View file

@ -197,10 +197,7 @@ impl Collection {
fn extract_latex_paths(&self, names: &mut HashSet<PathBuf>, flds: &str, notetype: &Notetype) {
for latex in extract_latex(flds, notetype.config.latex_svg).1 {
if is_local_base_name(&latex.fname) {
let path = self.media_folder.join(&latex.fname);
if path.exists() {
names.insert(path);
}
names.insert(self.media_folder.join(&latex.fname));
}
}
}
@ -238,11 +235,7 @@ impl CardTemplate {
for template_side in [&self.config.q_format, &self.config.a_format] {
for name in extract_underscored_references(template_side) {
if is_local_base_name(name) {
let path = media_folder.join(name);
// shotgun approach, so check if paths actually exist
if path.exists() {
names.insert(path);
}
names.insert(media_folder.join(name));
}
}
}

View file

@ -77,8 +77,11 @@ impl MediaIter {
)))
}
/// Skips missing paths.
pub(crate) fn from_file_list(list: impl IntoIterator<Item = PathBuf> + 'static) -> Self {
Self(Box::new(list.into_iter().map(Ok)))
Self(Box::new(
list.into_iter().filter(|path| path.exists()).map(Ok),
))
}
pub(crate) fn empty() -> Self {