don't allow empty files in media folder

This commit is contained in:
Damien Elmes 2012-05-16 05:35:58 +09:00
parent cdfaa664ed
commit 9aedb4a5e0
3 changed files with 20 additions and 1 deletions

View file

@ -42,7 +42,7 @@ MODEL_STD = 0
MODEL_CLOZE = 1
# deck schema & syncing vars
SCHEMA_VERSION = 8
SCHEMA_VERSION = 9
SYNC_ZIP_SIZE = int(2.5*1024*1024)
SYNC_URL = os.environ.get("SYNC_URL") or "https://beta.ankiweb.net/sync/"
SYNC_VER = 3

View file

@ -394,6 +394,10 @@ create table log (fname text primary key, type int);
continue
if f.lower() == "thumbs.db":
continue
# empty files are invalid; clean them up and continue
if not os.path.getsize(f):
os.unlink(f)
continue
# newly added?
if f not in self.cache:
added.append(f)

View file

@ -117,6 +117,21 @@ def _upgrade(col, ver):
col.db.execute(
"update cards set due = due / 1000 where due > 4294967296")
col.db.execute("update col set ver = 8")
if ver < 9:
# adding an empty file to a zip makes python's zip code think it's a
# folder, so remove any empty files
changed = False
for f in os.listdir(col.media.dir()):
if not os.path.getsize(f):
os.unlink(f)
col.media.db.execute(
"delete from log where fname = ?", f)
col.media.db.execute(
"delete from media where fname = ?", f)
changed = True
if changed:
col.media.db.commit()
col.db.execute("update col set ver = 9")
def _upgradeClozeModel(col, m):
m['type'] = MODEL_CLOZE