mirror of
https://github.com/ankitects/anki.git
synced 2025-12-01 08:57:12 -05:00
Wrap apkg import in transaction
This commit is contained in:
parent
1ba5444d7d
commit
7798b78c7d
2 changed files with 8 additions and 4 deletions
|
|
@ -90,12 +90,14 @@ impl SafeMediaEntry {
|
|||
}
|
||||
|
||||
impl Collection {
|
||||
pub fn import_apkg(&mut self, path: impl AsRef<Path>) -> Result<()> {
|
||||
pub fn import_apkg(&mut self, path: impl AsRef<Path>) -> Result<OpOutput<()>> {
|
||||
let file = File::open(path)?;
|
||||
let archive = ZipArchive::new(file)?;
|
||||
let mut ctx = Context::new(archive, self)?;
|
||||
ctx.import()?;
|
||||
Ok(())
|
||||
|
||||
self.transact(Op::Import, |col| {
|
||||
let mut ctx = Context::new(archive, col)?;
|
||||
ctx.import()
|
||||
})
|
||||
}
|
||||
|
||||
fn all_existing_sha1s(&mut self) -> Result<HashMap<String, [u8; 20]>> {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ pub enum Op {
|
|||
CreateCustomStudy,
|
||||
EmptyFilteredDeck,
|
||||
FindAndReplace,
|
||||
Import,
|
||||
RebuildFilteredDeck,
|
||||
RemoveDeck,
|
||||
RemoveNote,
|
||||
|
|
@ -55,6 +56,7 @@ impl Op {
|
|||
Op::AnswerCard => tr.actions_answer_card(),
|
||||
Op::Bury => tr.studying_bury(),
|
||||
Op::CreateCustomStudy => tr.actions_custom_study(),
|
||||
Op::Import => tr.actions_import(),
|
||||
Op::RemoveDeck => tr.decks_delete_deck(),
|
||||
Op::RemoveNote => tr.studying_delete_note(),
|
||||
Op::RenameDeck => tr.actions_rename_deck(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue