mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Actually get kobo db IOError workaround working
Tested on my Linux system by injecting a fake IOError
This commit is contained in:
parent
eda6dcb7e3
commit
18bc6081a9
@ -8,7 +8,7 @@ from contextlib import closing, suppress
|
|||||||
import apsw
|
import apsw
|
||||||
|
|
||||||
from calibre.prints import debug_print
|
from calibre.prints import debug_print
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile, TemporaryDirectory
|
||||||
|
|
||||||
|
|
||||||
def row_factory(cursor, row):
|
def row_factory(cursor, row):
|
||||||
@ -16,19 +16,15 @@ def row_factory(cursor, row):
|
|||||||
|
|
||||||
|
|
||||||
def copy_db(conn: apsw.Connection, dest_path: str):
|
def copy_db(conn: apsw.Connection, dest_path: str):
|
||||||
conn.cache_flush()
|
with suppress(AttributeError): # need a new enough version of apsw
|
||||||
with PersistentTemporaryFile() as f:
|
conn.cache_flush()
|
||||||
needs_remove = True
|
with TemporaryDirectory() as tdir:
|
||||||
try:
|
tempdb = os.path.join(tdir, 'temp.sqlite')
|
||||||
with closing(apsw.Connection(f.name)) as dest, conn.backup('main', dest, 'main') as b:
|
with closing(apsw.Connection(tempdb)) as dest, dest.backup('main', conn, 'main') as b:
|
||||||
while not b.done:
|
while not b.done:
|
||||||
b.step()
|
with suppress(apsw.BusyError, apsw.LockedError):
|
||||||
shutil.move(f.name, dest_path)
|
b.step()
|
||||||
needs_remove = False
|
shutil.move(tempdb, dest_path)
|
||||||
finally:
|
|
||||||
if needs_remove:
|
|
||||||
with suppress(OSError):
|
|
||||||
os.remove(f.name)
|
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user