prevent new users from downloading accidentally

This commit is contained in:
Damien Elmes 2018-09-05 19:53:41 +10:00
parent 18a7fb9dcd
commit d976bf913e
2 changed files with 12 additions and 1 deletions

View File

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

View File

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