From e1956f3cff411cebee1194ba8d00c88bcf689bb7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Jan 2024 12:23:33 +0530 Subject: [PATCH] Ignore a filenotfound error that happens during folder removal on windows despite exists() succeeding --- src/calibre/utils/copy_files.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/utils/copy_files.py b/src/calibre/utils/copy_files.py index 01f8cd2d1f..1a7bdb5936 100644 --- a/src/calibre/utils/copy_files.py +++ b/src/calibre/utils/copy_files.py @@ -284,6 +284,12 @@ def copy_tree( if delete_source and os.path.exists(make_long_path_useable(src)): try: shutil.rmtree(make_long_path_useable(src)) + except FileNotFoundError: + # some kind of delayed folder removal on handle close on Windows? Or exists() is succeeding but + # rmdir() is failing? Or something deleted the + # folder between the call to exists() and rmtree(). Windows is full + # of nanny programs that keep users safe from "themselves". + pass except OSError: if iswindows: time.sleep(WINDOWS_SLEEP_FOR_RETRY_TIME)