From 055b404165c0ba81d7a38aaeff4764f2dad9a74e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 26 Apr 2022 21:30:47 +1000 Subject: [PATCH] Add legacy arg to ExportAnkiPackage Currently not exposed on the frontend --- proto/anki/import_export.proto | 7 ++++--- pylib/anki/collection.py | 1 + rslib/src/backend/import_export.rs | 1 + rslib/src/import_export/package/apkg/export.rs | 8 +++++++- rslib/src/import_export/package/apkg/tests.rs | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/proto/anki/import_export.proto b/proto/anki/import_export.proto index 1c2d67b58..b2a4f1ae1 100644 --- a/proto/anki/import_export.proto +++ b/proto/anki/import_export.proto @@ -55,10 +55,11 @@ message ExportAnkiPackageRequest { string out_path = 1; bool with_scheduling = 2; bool with_media = 3; + bool legacy = 4; oneof selector { - generic.Empty whole_collection = 4; - int64 deck_id = 5; - notes.NoteIds note_ids = 6; + generic.Empty whole_collection = 5; + int64 deck_id = 6; + notes.NoteIds note_ids = 7; } } diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index a8c090855..b8fd54bbf 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -389,6 +389,7 @@ class Collection(DeprecatedNamesMixin): out_path=out_path, with_scheduling=with_scheduling, with_media=with_media, + legacy=True, **selector_kwarg, ) return self._backend.export_anki_package(request) diff --git a/rslib/src/backend/import_export.rs b/rslib/src/backend/import_export.rs index 52ad47f3e..cb5ee2ca6 100644 --- a/rslib/src/backend/import_export.rs +++ b/rslib/src/backend/import_export.rs @@ -66,6 +66,7 @@ impl ImportExportService for Backend { SearchNode::from_selector(selector), input.with_scheduling, input.with_media, + input.legacy, None, self.export_progress_fn(), ) diff --git a/rslib/src/import_export/package/apkg/export.rs b/rslib/src/import_export/package/apkg/export.rs index 49df6d786..c24bded2b 100644 --- a/rslib/src/import_export/package/apkg/export.rs +++ b/rslib/src/import_export/package/apkg/export.rs @@ -24,12 +24,14 @@ use crate::{ impl Collection { /// Returns number of exported notes. + #[allow(clippy::too_many_arguments)] pub fn export_apkg( &mut self, out_path: impl AsRef, search: impl TryIntoSearch, with_scheduling: bool, with_media: bool, + legacy: bool, media_fn: Option) -> MediaIter>>, progress_fn: impl FnMut(usize) -> Result<()>, ) -> Result { @@ -54,7 +56,11 @@ impl Collection { let col_size = temp_col.as_file().metadata()?.len() as usize; export_collection( - Meta::new_legacy(), + if legacy { + Meta::new_legacy() + } else { + Meta::new() + }, temp_apkg.path(), &mut temp_col, col_size, diff --git a/rslib/src/import_export/package/apkg/tests.rs b/rslib/src/import_export/package/apkg/tests.rs index 7997661a1..8b4a05456 100644 --- a/rslib/src/import_export/package/apkg/tests.rs +++ b/rslib/src/import_export/package/apkg/tests.rs @@ -35,6 +35,7 @@ fn roundtrip() { SearchNode::from_deck_name("parent::sample"), true, true, + true, None, |_| Ok(()), )