diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a3b1b1c6f84..7fad706c20c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -266,7 +266,7 @@ Yuuki Gabriele Patriarca SecretX Daniel Pechersky fernandolins <1887601+fernandolins@users.noreply.github.com> - +Helmut Carter ******************** The text of the 3 clause BSD license follows: diff --git a/rslib/src/backend/sync.rs b/rslib/src/backend/sync.rs index fc198e8da5a..8e30defee1a 100644 --- a/rslib/src/backend/sync.rs +++ b/rslib/src/backend/sync.rs @@ -200,9 +200,11 @@ impl Backend { task.take(); } } + let (abort_handle, abort_reg) = AbortHandle::new_pair(); + self.state.lock().unwrap().sync.media_sync_abort = Some(abort_handle); let backend = self.clone(); *task = Some(std::thread::spawn(move || { - backend.sync_media_blocking(auth, server_usn) + backend.sync_media_blocking(auth, server_usn, abort_reg) })); Ok(()) } @@ -238,15 +240,16 @@ impl Backend { &self, auth: SyncAuth, server_usn: Option, + abort_reg: AbortRegistration, ) -> Result<()> { - // abort handle - let (abort_handle, abort_reg) = AbortHandle::new_pair(); - self.state.lock().unwrap().sync.media_sync_abort = Some(abort_handle); + let _clear_abort_handle = scopeguard::guard(self.clone(), |backend| { + backend.state.lock().unwrap().sync.media_sync_abort.take(); + }); // start the sync let (mgr, progress) = { let mut col = self.col.lock().unwrap(); - let col = col.as_mut().unwrap(); + let col = col.as_mut().ok_or(AnkiError::CollectionNotOpen)?; (col.media()?, col.new_progress_handler()) }; let rt = self.runtime_handle(); @@ -254,9 +257,6 @@ impl Backend { let abortable_sync = Abortable::new(sync_fut, abort_reg); let result = rt.block_on(abortable_sync); - // clean up the handle - self.state.lock().unwrap().sync.media_sync_abort.take(); - // return result match result { Ok(sync_result) => sync_result,