if media is off, don't upgrade it

This commit is contained in:
Damien Elmes 2012-05-29 08:29:18 +09:00
parent 53cd0c5b9f
commit 8122c42245
2 changed files with 13 additions and 10 deletions

View file

@ -20,6 +20,7 @@ class MediaManager(object):
def __init__(self, col, server):
self.col = col
if server:
self._dir = None
return
# media directory
self._dir = re.sub("(?i)\.(anki2)$", ".media", self.col.path)

View file

@ -124,16 +124,18 @@ def _upgrade(col, ver):
# 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 os.path.isfile(f) and 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()
dir = col.media.dir()
if dir:
for f in os.listdir(col.media.dir()):
if os.path.isfile(f) and 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")
if ver < 10:
col.db.execute("""