mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
if media.db import fails, start anew
This commit is contained in:
parent
61b0072dcc
commit
eba3aa583c
1 changed files with 21 additions and 15 deletions
|
@ -3,6 +3,7 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
import urllib
|
import urllib
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import sys
|
import sys
|
||||||
|
@ -77,6 +78,7 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||||
def maybeUpgrade(self):
|
def maybeUpgrade(self):
|
||||||
oldpath = self.dir()+".db"
|
oldpath = self.dir()+".db"
|
||||||
if os.path.exists(oldpath):
|
if os.path.exists(oldpath):
|
||||||
|
try:
|
||||||
self.db.execute('attach "../collection.media.db" as old')
|
self.db.execute('attach "../collection.media.db" as old')
|
||||||
self.db.execute("""
|
self.db.execute("""
|
||||||
insert into media
|
insert into media
|
||||||
|
@ -92,6 +94,10 @@ insert into meta select dirMod, usn from old.meta
|
||||||
self.db.execute("detach old")
|
self.db.execute("detach old")
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
self.db.execute("vacuum analyze")
|
self.db.execute("vacuum analyze")
|
||||||
|
except Exception, e:
|
||||||
|
# if we couldn't import the old db for some reason, just start
|
||||||
|
# anew
|
||||||
|
self.col.log("failed to import old media db:"+traceback.format_exc())
|
||||||
os.rename("../collection.media.db", "../collection.media.db.old")
|
os.rename("../collection.media.db", "../collection.media.db.old")
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
Loading…
Reference in a new issue