Only show the Data files link if there is an actual file in the data folder, ignore sub-folders

This commit is contained in:
Kovid Goyal 2023-04-24 22:28:47 +05:30
parent 6a0b6f46de
commit 79cd85af35
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -219,8 +219,10 @@ def mi_to_html(
else: else:
data_path = os.path.join(path, DATA_DIR_NAME) data_path = os.path.join(path, DATA_DIR_NAME)
with suppress(OSError): with suppress(OSError):
if os.listdir(data_path): for de in os.scandir(data_path):
if de.is_file():
num_of_folders = 2 num_of_folders = 2
break
text = _('Book files') text = _('Book files')
name = ngettext('Folder:', 'Folders:', num_of_folders) name = ngettext('Folder:', 'Folders:', num_of_folders)
link = '<a href="{}" title="{}">{}</a>{}'.format(action(scheme, book_id=book_id, loc=loc), link = '<a href="{}" title="{}">{}</a>{}'.format(action(scheme, book_id=book_id, loc=loc),