From 3e97ae74d612f1a64724922a6ff9bce4703e7fea Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Mar 2022 08:40:36 +0530 Subject: [PATCH] Only retry for specific error codes --- src/calibre/utils/config_base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/utils/config_base.py b/src/calibre/utils/config_base.py index 3f6ba6c56c..6dd0180ca7 100644 --- a/src/calibre/utils/config_base.py +++ b/src/calibre/utils/config_base.py @@ -346,13 +346,17 @@ class ConfigInterface: def retry_on_fail(func, *args, count=10, sleep_time=0.2): import time + ERROR_SHARING_VIOLATION = 32 + ACCESS_DENIED = 5 for i in range(count): try: return func(*args) except FileNotFoundError: raise - except OSError: - if not iswindows or i > count - 2: + except OSError as e: + # Windows stupidly gives us an ACCESS_DENIED rather than a + # ERROR_SHARING_VIOLATION if the file is open + if not iswindows or i > count - 2 or e.winerror not in (ERROR_SHARING_VIOLATION, ACCESS_DENIED): raise # Try the operation repeatedly in case something like a virus # scanner has opened one of the files (I love windows)