Note id, not guid of conflicting notes

This commit is contained in:
RumovZ 2022-04-07 21:08:17 +02:00
parent 94a6cdd6ed
commit 48bc6627b1

View file

@ -44,7 +44,9 @@ struct Context<'a> {
/// original, normalized file name → (refererenced on import material, /// original, normalized file name → (refererenced on import material,
/// entry with possibly remapped file name) /// entry with possibly remapped file name)
used_media_entries: HashMap<String, (bool, SafeMediaEntry)>, used_media_entries: HashMap<String, (bool, SafeMediaEntry)>,
conflicting_notes: HashSet<String>, /// Source notes that cannot be imported, because notes with the same guid
/// exist in the target, but their notetypes don't match.
conflicting_notes: HashSet<NoteId>,
normalize_notes: bool, normalize_notes: bool,
} }
@ -220,14 +222,14 @@ impl<'a> Context<'a> {
for mut note in mem::take(&mut self.data.notes) { for mut note in mem::take(&mut self.data.notes) {
if let Some(notetype_id) = self.remapped_notetypes.get(&note.notetype_id) { if let Some(notetype_id) = self.remapped_notetypes.get(&note.notetype_id) {
if self.guid_map.contains_key(&note.guid) { if self.guid_map.contains_key(&note.guid) {
self.conflicting_notes.insert(note.guid); self.conflicting_notes.insert(note.id);
// TODO: Log ignore // TODO: Log ignore
} else { } else {
note.notetype_id = *notetype_id; note.notetype_id = *notetype_id;
self.add_note(&mut note)?; self.add_note(&mut note)?;
} }
} else if let Some(&meta) = self.guid_map.get(&note.guid) { } else if let Some(&meta) = self.guid_map.get(&note.guid) {
self.maybe_update_note(note, meta)?; self.maybe_update_note(&mut note, meta)?;
} else { } else {
self.add_note(&mut note)?; self.add_note(&mut note)?;
} }
@ -261,13 +263,14 @@ impl<'a> Context<'a> {
.ok_or(AnkiError::NotFound) .ok_or(AnkiError::NotFound)
} }
fn maybe_update_note(&mut self, mut note: Note, meta: NoteMeta) -> Result<()> { fn maybe_update_note(&mut self, note: &mut Note, meta: NoteMeta) -> Result<()> {
if meta.mtime < note.mtime { if meta.mtime < note.mtime {
if meta.notetype_id == note.notetype_id { if meta.notetype_id == note.notetype_id {
self.remapped_notes.insert(note.id, meta.id);
note.id = meta.id; note.id = meta.id;
self.update_note(&mut note)?; self.update_note(note)?;
} else { } else {
self.conflicting_notes.insert(note.guid); self.conflicting_notes.insert(note.id);
// TODO: Log ignore // TODO: Log ignore
} }
} else { } else {