add upper bound to # of media files in single zip

This commit is contained in:
Damien Elmes 2013-04-11 14:13:11 +09:00
parent c437a38446
commit f3f7835032
2 changed files with 3 additions and 2 deletions

View File

@ -44,6 +44,7 @@ MODEL_CLOZE = 1
# deck schema & syncing vars
SCHEMA_VERSION = 11
SYNC_ZIP_SIZE = int(2.5*1024*1024)
SYNC_ZIP_COUNT = 300
SYNC_URL = os.environ.get("SYNC_URL") or "https://ankiweb.net/sync/"
SYNC_VER = 5

View File

@ -310,7 +310,7 @@ If the same name exists, compare checksums."""
# and place a json file in the zip with the necessary information.
def zipAdded(self):
"Add files to a zip until over SYNC_ZIP_SIZE. Return zip data."
"Add files to a zip until over SYNC_ZIP_SIZE/COUNT. Return zip data."
f = StringIO()
z = zipfile.ZipFile(f, "w", compression=zipfile.ZIP_DEFLATED)
sz = 0
@ -330,7 +330,7 @@ If the same name exists, compare checksums."""
z.write(fname, str(cnt))
files[str(cnt)] = fname
sz += os.path.getsize(fname)
if sz > SYNC_ZIP_SIZE:
if sz > SYNC_ZIP_SIZE or cnt > SYNC_ZIP_COUNT:
break
cnt += 1
z.writestr("_meta", json.dumps(files))