Windows: Fix error when applying hyphenation in bulk with Polish books. Fixes #1873949 [Bulk Polishing fails with 'Access Denied'](https://bugs.launchpad.net/calibre/+bug/1873949)

This commit is contained in:
Kovid Goyal 2020-04-23 09:13:23 +05:30
parent 3d6c8dd286
commit 0d033196fc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -13,6 +13,7 @@ from io import BytesIO
from calibre.constants import cache_dir from calibre.constants import cache_dir
from calibre.ptempfile import TemporaryDirectory from calibre.ptempfile import TemporaryDirectory
from calibre.utils.localization import lang_as_iso639_1 from calibre.utils.localization import lang_as_iso639_1
from calibre.utils.lock import ExclusiveFile
from polyglot.builtins import iteritems from polyglot.builtins import iteritems
from polyglot.functools import lru_cache from polyglot.functools import lru_cache
@ -79,10 +80,12 @@ def extract_dicts(cache_path):
def is_cache_up_to_date(cache_path): def is_cache_up_to_date(cache_path):
if getattr(is_cache_up_to_date, 'updated', False): if getattr(is_cache_up_to_date, 'updated', False):
return True return True
hsh = P('hyphenation/sha1sum', data=True) hsh = P('hyphenation/sha1sum', data=True, allow_user_override=False)
try: try:
with open(os.path.join(cache_path, 'f', 'sha1sum'), 'rb') as f: with open(os.path.join(cache_path, 'f', 'sha1sum'), 'rb') as f:
return f.read() == hsh if f.read() == hsh:
is_cache_up_to_date.updated = True
return True
except EnvironmentError: except EnvironmentError:
pass pass
return False return False
@ -102,8 +105,9 @@ def get_cache_path(cd):
def path_to_dictionary(dictionary_name, cache_callback=None): def path_to_dictionary(dictionary_name, cache_callback=None):
cd = getattr(path_to_dictionary, 'cache_dir', None) or cache_dir() cd = getattr(path_to_dictionary, 'cache_dir', None) or cache_dir()
cache_path = get_cache_path(cd) cache_path = get_cache_path(cd)
if not is_cache_up_to_date(cache_path): with ExclusiveFile(os.path.join(cache_path, 'lock')):
extract_dicts(cache_path) if not is_cache_up_to_date(cache_path):
if cache_callback is not None: extract_dicts(cache_path)
cache_callback() if cache_callback is not None:
cache_callback()
return os.path.join(cache_path, 'f', dictionary_name) return os.path.join(cache_path, 'f', dictionary_name)