mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-22 17:48:09 +00:00
Bug Fix: preserve original file mtime during HTML entity resolution to prevent infinite refresh loop
This commit is contained in:
parent
6f516c0074
commit
dd97b642c7
1 changed files with 13 additions and 0 deletions
|
|
@ -94,6 +94,15 @@ def _resolve_html_entities(file_path):
|
|||
header = f.read(200)
|
||||
encoding = _detect_xml_encoding(header)
|
||||
|
||||
# Capture the original mtime before modifying the file so that os.replace()
|
||||
# does not update the file's mtime. The file watcher in core/tasks.py uses
|
||||
# mtime to detect changes; if we let mtime advance it would trigger an
|
||||
# infinite refresh loop for local file-based EPG sources.
|
||||
try:
|
||||
original_stat = os.stat(file_path)
|
||||
except OSError:
|
||||
original_stat = None
|
||||
|
||||
temp_path = file_path + '.entity_tmp'
|
||||
success = False
|
||||
try:
|
||||
|
|
@ -102,6 +111,10 @@ def _resolve_html_entities(file_path):
|
|||
for line in src:
|
||||
dst.write(_NAMED_ENTITY_RE.sub(_replace_html_entity, line))
|
||||
os.replace(temp_path, file_path)
|
||||
# Restore the original mtime (and atime) so the file watcher does not
|
||||
# mistake the rewrite for an external update.
|
||||
if original_stat is not None:
|
||||
os.utime(file_path, (original_stat.st_atime, original_stat.st_mtime))
|
||||
success = True
|
||||
logger.debug(f"Resolved HTML entities in {file_path} (encoding: {encoding})")
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue