fix backup not being taken before full download

This commit is contained in:
Damien Elmes 2021-02-06 19:01:48 +10:00
parent 3cd311191a
commit b7c72bca4c
2 changed files with 17 additions and 4 deletions

View file

@ -565,6 +565,13 @@ class AnkiQt(QMainWindow):
if not corrupt and not self.restoringBackup:
self.backup()
def _close_for_full_download(self) -> None:
"Backup and prepare collection to be overwritten."
self.col.close(downgrade=False)
self.backup()
self.col.reopen(after_full_sync=False)
self.col.close_for_full_sync()
# Backup and auto-optimize
##########################################################################
@ -585,6 +592,9 @@ class AnkiQt(QMainWindow):
z.close()
def backup(self) -> None:
"Read data into memory, and complete backup on a background thread."
assert not self.col or not self.col.db
nbacks = self.pm.profile["numBackups"]
if not nbacks or devMode:
return
@ -615,7 +625,8 @@ class AnkiQt(QMainWindow):
fname = backups.pop(0)
path = os.path.join(dir, fname)
os.unlink(path)
gui_hooks.backup_did_complete()
self.taskman.run_on_main(gui_hooks.backup_did_complete)
def maybeOptimize(self) -> None:
# have two weeks passed?

View file

@ -173,8 +173,6 @@ def on_full_sync_timer(mw: aqt.main.AnkiQt) -> None:
def full_download(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
mw.col.close_for_full_sync()
def on_timer() -> None:
on_full_sync_timer(mw)
@ -182,6 +180,10 @@ def full_download(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
qconnect(timer.timeout, on_timer)
timer.start(150)
def download() -> None:
mw._close_for_full_download()
mw.col.full_download(mw.pm.sync_auth())
def on_future_done(fut: Future) -> None:
timer.stop()
mw.col.reopen(after_full_sync=True)
@ -194,7 +196,7 @@ def full_download(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
return on_done()
mw.taskman.with_progress(
lambda: mw.col.full_download(mw.pm.sync_auth()),
download,
on_future_done,
label=tr(TR.SYNC_DOWNLOADING_FROM_ANKIWEB),
)