mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
don't allow empty files in media folder
This commit is contained in:
parent
cdfaa664ed
commit
9aedb4a5e0
3 changed files with 20 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue