From 86dab6d6cc89e536a99300f7e1dcbf1052317ff5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 2 Jul 2018 18:01:13 +0530 Subject: [PATCH] When exporting very large libraries fix failures due to busy errors. Fixes #1779664 [Error-message when exporting library for Backup](https://bugs.launchpad.net/calibre/+bug/1779664) --- src/calibre/db/backend.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index e4c2e9d7af..d68370ccbe 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1788,14 +1788,13 @@ class DB(object): self.executemany('INSERT INTO data (book,format,uncompressed_size,name) VALUES (?,?,?,?)', vals) def backup_database(self, path): - # We have to open a new connection to self.dbpath, until this issue is fixed: - # https://github.com/rogerbinns/apsw/issues/199 dest_db = apsw.Connection(path) - source = apsw.Connection(self.dbpath) - with dest_db.backup('main', source, 'main') as b: + with dest_db.backup('main', self.conn, 'main') as b: while not b.done: - b.step(100) - source.close() + try: + b.step(100) + except apsw.BusyError: + pass dest_db.cursor().execute('DELETE FROM metadata_dirtied; VACUUM;') dest_db.close()