Files
changedetection.io/changedetectionio
dgtlmoonandClaude Opus 5 1dd6291667 Judge favicon expiry on the icon the watch actually has, not whatever glob lists first (#4434)
* Judge favicon expiry on the icon the watch actually has, not whatever glob lists first

bump_favicon() names the saved file after the icon's type (favicon.png, favicon.ico, ...)
and did not remove a previous save under a different extension, so a watch whose icon
changed type ends up holding more than one favicon.*.

favicon_is_expired() then picked next(iter(glob.glob("favicon.*"))). glob order is
os.scandir order - stable, but decided by filename hash - so for some extension pairs the
stale file wins every single time, its age always exceeds the 24h threshold, and the
favicon is refetched on every check forever. Measured across realistic pairs, 3 of 10
lose that way:

  old=.png new=.ico   -> glob lists favicon.png first  -> always expired
  old=.ico new=.svg   -> glob lists favicon.ico first  -> always expired
  old=.png new=.webp  -> glob lists favicon.png first  -> always expired

That is an in-page network fetch through the watch's proxy on every check, plus the
favicon fetcher's own sequential per-icon timeouts, for a favicon that is already saved
and current.

Fixed at both ends: pick the newest candidate by mtime, and have bump_favicon() drop
superseded files so the ambiguity stops arising.

Also tidied two things in the same function:

- os.path.isfile(None) raised a TypeError when the module-level filename cache said yes
  after the file had been removed, which the broad except turned into a logger.critical()
  for an entirely benign condition. The empty case is now handled explicitly.
- the broad except stays (this runs inline on the check path as an argument to
  fetcher.run(), so it must never fail a watch) but logs at warning, since the only cost
  of getting this wrong is one extra favicon fetch.

Tests fail on master (favicon.ico left behind; fresh icon reported expired) and pass here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Favicon - write the new icon before removing superseded ones, so a failed write keeps the old icon

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-23 12:04:17 +02:00
..
…