From dd186d060ddef1890df0300b69710b3bba52fe26 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Apr 2023 11:08:03 +0530 Subject: [PATCH] Update paths and filenames in db in a single transaction --- src/calibre/db/backend.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index f9b3c06208..a15aa820cd 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1775,9 +1775,10 @@ class DB: self.copy_format_to(book_id, fmt, ofmt_fname, current_path, dest, windows_atomic_move=wam, use_hardlink=True) # Update db to reflect new file locations - for fmt in formats: - formats_field.table.set_fname(book_id, fmt, fname, self) - path_field.table.set_path(book_id, path, self) + with self.conn: + for fmt in formats: + formats_field.table.set_fname(book_id, fmt, fname, self) + path_field.table.set_path(book_id, path, self) # Delete not needed files and directories if source_ok: