diff --git a/ftl/core/importing.ftl b/ftl/core/importing.ftl index 99203d313..6f70629e3 100644 --- a/ftl/core/importing.ftl +++ b/ftl/core/importing.ftl @@ -34,8 +34,8 @@ importing-mnemosyne-20-deck-db = Mnemosyne 2.0 Deck (*.db) importing-multicharacter-separators-are-not-supported-please = Multi-character separators are not supported. Please enter one character only. importing-notes-added-from-file = Notes added from file: { $val } importing-notes-found-in-file = Notes found in file: { $val } -importing-notes-skipped-as-theyre-already-in = Notes skipped, as they're already in your collection: { $val } -importing-notes-that-could-not-be-imported = Notes that could not be imported as note type has changed: { $val } +importing-notes-skipped-as-theyre-already-in = Notes skipped, as up-to-date copies are already in your collection: { $val } +importing-notes-skipped-update-due-to-notetype = Notes not updated, as notetype has been modified since you first imported the notes: { $val } importing-notes-updated-as-file-had-newer = Notes updated, as file had newer version: { $val } importing-packaged-anki-deckcollection-apkg-colpkg-zip = Packaged Anki Deck/Collection (*.apkg *.colpkg *.zip) importing-pauker-18-lesson-paugz = Pauker 1.8 Lesson (*.pau.gz) @@ -120,3 +120,4 @@ importing-cards-added = importing-importing-collection = Importing collection... importing-unable-to-import-filename = Unable to import { $filename }: file type not supported +importing-notes-that-could-not-be-imported = Notes that could not be imported as note type has changed: { $val } diff --git a/pylib/anki/importing/anki2.py b/pylib/anki/importing/anki2.py index 5efbd7c5d..21ca6800b 100644 --- a/pylib/anki/importing/anki2.py +++ b/pylib/anki/importing/anki2.py @@ -150,7 +150,7 @@ class Anki2Importer(Importer): if dupesIgnored: self.log.append( - self.dst.tr.importing_notes_that_could_not_be_imported( + self.dst.tr.importing_notes_skipped_update_due_to_notetype( val=len(dupesIgnored) ) ) diff --git a/qt/aqt/import_export/importing.py b/qt/aqt/import_export/importing.py index 7609a86f0..7302dc267 100644 --- a/qt/aqt/import_export/importing.py +++ b/qt/aqt/import_export/importing.py @@ -289,7 +289,7 @@ def log_queues(log: ImportLogWithChanges.Log) -> Tuple[LogQueue, ...]: return ( LogQueue( log.conflicting, - tr.importing_notes_that_could_not_be_imported, + tr.importing_notes_skipped_update_due_to_notetype, tr.importing_skipped(), ), LogQueue( diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 50fd50976..7879f238f 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -651,7 +651,7 @@ def running_in_sandbox(): ) != "" ) - in_snap = os.environ.get("SNAP") != "" + in_snap = bool(os.environ.get("SNAP")) return in_flatpak or in_snap diff --git a/rslib/src/import_export/package/apkg/import/notes.rs b/rslib/src/import_export/package/apkg/import/notes.rs index d7f2e313a..4782e1280 100644 --- a/rslib/src/import_export/package/apkg/import/notes.rs +++ b/rslib/src/import_export/package/apkg/import/notes.rs @@ -170,19 +170,30 @@ impl<'n> NoteContext<'n> { for mut note in notes { incrementor.increment()?; - if let Some(notetype_id) = self.remapped_notetypes.get(¬e.notetype_id) { - if self.target_guids.contains_key(¬e.guid) { - self.imports.log_conflicting(note); + let remapped_notetype_id = self.remapped_notetypes.get(¬e.notetype_id); + if let Some(existing_note) = self.target_guids.get(¬e.guid) { + if existing_note.mtime < note.mtime { + if existing_note.notetype_id != note.notetype_id + || remapped_notetype_id.is_some() + { + // Existing GUID with different notetype id, or changed notetype schema + self.imports.log_conflicting(note); + } else { + self.update_note(note, existing_note.id)?; + } } else { - note.notetype_id = *notetype_id; - self.add_note(note)?; + self.imports.log_duplicate(note, existing_note.id); } - } else if let Some(&meta) = self.target_guids.get(¬e.guid) { - self.maybe_update_note(note, meta)?; } else { + if let Some(remapped_ntid) = remapped_notetype_id { + // Notetypes have diverged, but this is a new note, so we can import + // with a new notetype id. + note.notetype_id = *remapped_ntid; + } self.add_note(note)?; } } + Ok(()) } @@ -217,19 +228,6 @@ impl<'n> NoteContext<'n> { self.target_col.storage.get_note(nid)?.or_not_found(nid) } - fn maybe_update_note(&mut self, note: Note, meta: NoteMeta) -> Result<()> { - if meta.mtime < note.mtime { - if meta.notetype_id == note.notetype_id { - self.update_note(note, meta.id)?; - } else { - self.imports.log_conflicting(note); - } - } else { - self.imports.log_duplicate(note, meta.id); - } - Ok(()) - } - fn update_note(&mut self, mut note: Note, target_id: NoteId) -> Result<()> { let source_id = note.id; note.id = target_id;