From e4d3a372c8107b77f767f870bfe0da954974a32b Mon Sep 17 00:00:00 2001 From: CaliBrain Date: Fri, 29 Aug 2025 22:32:04 -0400 Subject: [PATCH] Add retry logic for failed file copy (#261) --- backend.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend.py b/backend.py index 555bcd7e..83016424 100644 --- a/backend.py +++ b/backend.py @@ -180,8 +180,12 @@ def _download_book_with_cancellation(book_id: str, cancel_flag: Event) -> Option try: shutil.move(book_path, intermediate_path) except Exception as e: - logger.debug(f"Error moving book: {e}, will try copying instead") - shutil.copy(book_path, intermediate_path) + try: + logger.debug(f"Error moving book: {e}, will try copying instead") + shutil.move(book_path, intermediate_path) + except Exception as e: + logger.debug(f"Error copying book: {e}, will try copying without permissions instead") + shutil.copyfile(book_path, intermediate_path) os.remove(book_path) # Final cancellation check before completing