fix(coverimage): fix operator precedence and parameter usage in cache functions#15032
Merged
Merged
Conversation
… functions Fix two bugs in the coverimage plugin: 1. cleanCache(): Fix operator precedence in while loop condition. In Lua, `and` has higher precedence than `or`, so the bounds check `index <= #files` was only applied to the cache size condition, not the file count condition. Added parentheses to ensure the bounds check applies to both conditions. 2. getCacheFiles(): Use the function parameters `cache_path` and `cache_prefix` consistently instead of mixing them with `self.cover_image_cache_path` and `self.cover_image_cache_prefix`.
Frenzie
reviewed
Feb 23, 2026
| or (cache_size > self.cover_image_cache_maxsize * 1000 * 1000 and self.cover_image_cache_maxsize ~= 0) | ||
| while ((cache_count > self.cover_image_cache_maxfiles and self.cover_image_cache_maxfiles ~= 0) | ||
| or (cache_size > self.cover_image_cache_maxsize * 1000 * 1000 and self.cover_image_cache_maxsize ~= 0)) | ||
| and index <= #files do |
Member
There was a problem hiding this comment.
If it's supposed to apply to both I'd put it first.
Move `index <= #files` to the beginning of the while condition for clarity and to benefit from short-circuit evaluation.
poire-z
reviewed
Feb 23, 2026
poire-z
left a comment
Contributor
There was a problem hiding this comment.
Fine with me. Not familiar at all with this plugin, but the changes looks logical.
Comment on lines
+314
to
317
| while index <= #files | ||
| and ((cache_count > self.cover_image_cache_maxfiles and self.cover_image_cache_maxfiles ~= 0) | ||
| or (cache_size > self.cover_image_cache_maxsize * 1000 * 1000 and self.cover_image_cache_maxsize ~= 0)) do | ||
| os.remove(files[index].name) |
Contributor
There was a problem hiding this comment.
(I would indent more the and and or lines, so they visually look more like a continuation of the while line, than just operation in the while branch like os.remove() - but that's just me :))
Member
There was a problem hiding this comment.
It was that way already, so I'll just leave it be.
0xstillb
pushed a commit
to 0xstillb/koreader-thai
that referenced
this pull request
May 9, 2026
… functions (koreader#15032) Fix two bugs in the coverimage plugin: 1. cleanCache(): Fix operator precedence in while loop condition. In Lua, `and` has higher precedence than `or`, so the bounds check `index <= #files` was only applied to the cache size condition, not the file count condition. Added parentheses to ensure the bounds check applies to both conditions. 2. getCacheFiles(): Use the function parameters `cache_path` and `cache_prefix` consistently instead of mixing them with `self.cover_image_cache_path` and `self.cover_image_cache_prefix`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cleanCache(): Fix operator precedence in while loop condition. In Lua,andhas higher precedence thanor, so the bounds checkindex <= #fileswas only applied to the cache size condition, not the file count condition. Added parentheses to ensure the bounds check applies to both conditions.getCacheFiles(): Use the function parameterscache_pathandcache_prefixconsistently instead of mixing them withself.cover_image_cache_pathandself.cover_image_cache_prefix.This change is