Wrap apkg import in transaction

This commit is contained in:
RumovZ 2022-04-09 15:35:16 +02:00
parent 1ba5444d7d
commit 7798b78c7d
2 changed files with 8 additions and 4 deletions

View file

@ -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]>> {

View file

@ -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(),