From 3bb41aca6de1e84b5d0e862224943719eb0ad4da Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 6 Feb 2022 18:57:58 +0100 Subject: [PATCH] Bugfix for already present mobi file during convert (fixes #1900) --- cps/tasks/convert.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 596bf95c..90513b09 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -116,8 +116,20 @@ class TaskConvert(CalibreTask): log.info("Book id %d already converted to %s", book_id, format_new_ext) cur_book = local_db.get_book(book_id) self.title = cur_book.title - self.results['path'] = file_path + self.results['path'] = cur_book.path self.results['title'] = self.title + new_format = db.Data(name=os.path.basename(file_path), + book_format=self.settings['new_book_format'].upper(), + book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext)) + try: + local_db.session.merge(new_format) + local_db.session.commit() + except SQLAlchemyError as e: + local_db.session.rollback() + log.error("Database error: %s", e) + local_db.session.close() + self._handleError(error_message) + return self._handleSuccess() local_db.session.close() return os.path.basename(file_path + format_new_ext)