prevent new users from downloading accidentally
This commit is contained in:
parent
18a7fb9dcd
commit
d976bf913e
@ -634,6 +634,7 @@ class FullSyncer(HttpSyncer):
|
|||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
runHook("sync", "download")
|
runHook("sync", "download")
|
||||||
|
localNotEmpty = self.col.db.scalar("select 1 from cards")
|
||||||
self.col.close()
|
self.col.close()
|
||||||
cont = self.req("download")
|
cont = self.req("download")
|
||||||
tpath = self.col.path + ".tmp"
|
tpath = self.col.path + ".tmp"
|
||||||
@ -644,7 +645,12 @@ class FullSyncer(HttpSyncer):
|
|||||||
# check the received file is ok
|
# check the received file is ok
|
||||||
d = DB(tpath)
|
d = DB(tpath)
|
||||||
assert d.scalar("pragma integrity_check") == "ok"
|
assert d.scalar("pragma integrity_check") == "ok"
|
||||||
|
remoteEmpty = not d.scalar("select 1 from cards")
|
||||||
d.close()
|
d.close()
|
||||||
|
# accidental clobber?
|
||||||
|
if localNotEmpty and remoteEmpty:
|
||||||
|
os.unlink(tpath)
|
||||||
|
return "downloadClobber"
|
||||||
# overwrite existing collection
|
# overwrite existing collection
|
||||||
os.unlink(self.col.path)
|
os.unlink(self.col.path)
|
||||||
os.rename(tpath, self.col.path)
|
os.rename(tpath, self.col.path)
|
||||||
|
@ -142,6 +142,8 @@ sync again to correct the issue."""))
|
|||||||
pass
|
pass
|
||||||
elif evt == "fullSync":
|
elif evt == "fullSync":
|
||||||
self._confirmFullSync()
|
self._confirmFullSync()
|
||||||
|
elif evt == "downloadClobber":
|
||||||
|
showInfo(_("Your AnkiWeb collection does not contain any cards. Please sync again and choose 'Upload' instead."))
|
||||||
elif evt == "send":
|
elif evt == "send":
|
||||||
# posted events not guaranteed to arrive in order
|
# posted events not guaranteed to arrive in order
|
||||||
self.sentBytes = max(self.sentBytes, int(args[0]))
|
self.sentBytes = max(self.sentBytes, int(args[0]))
|
||||||
@ -431,7 +433,10 @@ class SyncThread(QThread):
|
|||||||
if not self.client.upload():
|
if not self.client.upload():
|
||||||
self.fireEvent("upbad")
|
self.fireEvent("upbad")
|
||||||
else:
|
else:
|
||||||
self.client.download()
|
ret = self.client.download()
|
||||||
|
if ret == "downloadClobber":
|
||||||
|
self.fireEvent(ret)
|
||||||
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "sync cancelled" in str(e):
|
if "sync cancelled" in str(e):
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user