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
|
||||
|
||||
from calibre.prints import debug_print
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.ptempfile import PersistentTemporaryFile, TemporaryDirectory
|
||||
|
||||
|
||||
def row_factory(cursor, row):
|
||||
@ -16,19 +16,15 @@ def row_factory(cursor, row):
|
||||
|
||||
|
||||
def copy_db(conn: apsw.Connection, dest_path: str):
|
||||
with suppress(AttributeError): # need a new enough version of apsw
|
||||
conn.cache_flush()
|
||||
with PersistentTemporaryFile() as f:
|
||||
needs_remove = True
|
||||
try:
|
||||
with closing(apsw.Connection(f.name)) as dest, conn.backup('main', dest, 'main') as b:
|
||||
with TemporaryDirectory() as tdir:
|
||||
tempdb = os.path.join(tdir, 'temp.sqlite')
|
||||
with closing(apsw.Connection(tempdb)) as dest, dest.backup('main', conn, 'main') as b:
|
||||
while not b.done:
|
||||
with suppress(apsw.BusyError, apsw.LockedError):
|
||||
b.step()
|
||||
shutil.move(f.name, dest_path)
|
||||
needs_remove = False
|
||||
finally:
|
||||
if needs_remove:
|
||||
with suppress(OSError):
|
||||
os.remove(f.name)
|
||||
shutil.move(tempdb, dest_path)
|
||||
|
||||
|
||||
class Database:
|
||||
|
Loading…
x
Reference in New Issue
Block a user