mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
must make sure to detach old media db before renaming
This commit is contained in:
parent
a5d9131445
commit
1cb2aa077a
1 changed files with 2 additions and 3 deletions
|
@ -78,8 +78,8 @@ 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):
|
||||||
|
self.db.execute('attach "../collection.media.db" as old')
|
||||||
try:
|
try:
|
||||||
self.db.execute('attach "../collection.media.db" as old')
|
|
||||||
self.db.execute("""
|
self.db.execute("""
|
||||||
insert into media
|
insert into media
|
||||||
select m.fname, csum, mod, ifnull((select 1 from log l2 where l2.fname=m.fname), 0) as dirty
|
select m.fname, csum, mod, ifnull((select 1 from log l2 where l2.fname=m.fname), 0) as dirty
|
||||||
|
@ -91,13 +91,12 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||||
self.db.execute("""
|
self.db.execute("""
|
||||||
insert into meta select dirMod, usn from old.meta
|
insert into meta select dirMod, usn from old.meta
|
||||||
""")
|
""")
|
||||||
self.db.execute("detach old")
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
self.db.execute("vacuum analyze")
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
# if we couldn't import the old db for some reason, just start
|
# if we couldn't import the old db for some reason, just start
|
||||||
# anew
|
# anew
|
||||||
self.col.log("failed to import old media db:"+traceback.format_exc())
|
self.col.log("failed to import old media db:"+traceback.format_exc())
|
||||||
|
self.db.execute("detach old")
|
||||||
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