fix backup not being taken before full download

This commit is contained in:
Damien Elmes 2021-02-06 19:01:48 +10:00
parent 5a54d5e07d
commit 0981d8d0de
2 changed files with 19 additions and 6 deletions

View file

@ -557,6 +557,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
##########################################################################
@ -577,6 +584,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
@ -607,7 +617,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

@ -172,16 +172,18 @@ 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():
def on_timer() -> None:
on_full_sync_timer(mw)
timer = QTimer(mw)
qconnect(timer.timeout, on_timer)
timer.start(150)
def on_future_done(fut):
def download() -> None:
mw._close_for_full_download()
mw.col.backend.full_download(mw.pm.sync_auth())
def on_future_done(fut) -> None:
timer.stop()
mw.col.reopen(after_full_sync=True)
mw.reset()
@ -193,7 +195,7 @@ def full_download(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None:
return on_done()
mw.taskman.with_progress(
lambda: mw.col.backend.full_download(mw.pm.sync_auth()),
download,
on_future_done,
label=tr(TR.SYNC_DOWNLOADING_FROM_ANKIWEB),
)