From d976bf913eef932acde4dddba5408ec78ab287f8 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 5 Sep 2018 19:53:41 +1000 Subject: [PATCH] prevent new users from downloading accidentally --- anki/sync.py | 6 ++++++ aqt/sync.py | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/anki/sync.py b/anki/sync.py index b585f5bc2..df1cc7e65 100644 --- a/anki/sync.py +++ b/anki/sync.py @@ -634,6 +634,7 @@ class FullSyncer(HttpSyncer): def download(self): runHook("sync", "download") + localNotEmpty = self.col.db.scalar("select 1 from cards") self.col.close() cont = self.req("download") tpath = self.col.path + ".tmp" @@ -644,7 +645,12 @@ class FullSyncer(HttpSyncer): # check the received file is ok d = DB(tpath) assert d.scalar("pragma integrity_check") == "ok" + remoteEmpty = not d.scalar("select 1 from cards") d.close() + # accidental clobber? + if localNotEmpty and remoteEmpty: + os.unlink(tpath) + return "downloadClobber" # overwrite existing collection os.unlink(self.col.path) os.rename(tpath, self.col.path) diff --git a/aqt/sync.py b/aqt/sync.py index 28dde3225..a5f425918 100644 --- a/aqt/sync.py +++ b/aqt/sync.py @@ -142,6 +142,8 @@ sync again to correct the issue.""")) pass elif evt == "fullSync": self._confirmFullSync() + elif evt == "downloadClobber": + showInfo(_("Your AnkiWeb collection does not contain any cards. Please sync again and choose 'Upload' instead.")) elif evt == "send": # posted events not guaranteed to arrive in order self.sentBytes = max(self.sentBytes, int(args[0])) @@ -431,7 +433,10 @@ class SyncThread(QThread): if not self.client.upload(): self.fireEvent("upbad") else: - self.client.download() + ret = self.client.download() + if ret == "downloadClobber": + self.fireEvent(ret) + return except Exception as e: if "sync cancelled" in str(e): return