From f3f7835032bb25bfbcc43d6607b3b4a45507e5ed Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 11 Apr 2013 14:13:11 +0900 Subject: [PATCH] add upper bound to # of media files in single zip --- anki/consts.py | 1 + anki/media.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/anki/consts.py b/anki/consts.py index e2427a16b..77651e478 100644 --- a/anki/consts.py +++ b/anki/consts.py @@ -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 diff --git a/anki/media.py b/anki/media.py index 09676da9f..2fda0d652 100644 --- a/anki/media.py +++ b/anki/media.py @@ -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))