Skip to content

Commit

Permalink
fix: prevent temporary cover images conflicts in caches bayang#41
Browse files Browse the repository at this point in the history
  • Loading branch information
bayang committed Sep 13, 2022
1 parent ea859d9 commit b1482e1
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,19 @@ class FetchMetadataService(
commandArray.add("-p")
commandArray.add("Amazon.com")
}
bookFileName += ".jpg"
// add a bit of randomness to prevent images with same names.
// Otherwise different files with same names are cached, see issue #41
val now = System.currentTimeMillis()
bookFileName += "-$now.jpg"
val targetCover = File(properties.files.images, bookFileName)
if (targetCover != null && targetCover.exists()) {
try {
val deleted = targetCover.delete()
logger.trace { "deleted already existing cover temporary image ${targetCover.absolutePath}" }
} catch (e: Exception) {
logger.error(e) { "failed to delete image ${targetCover.absolutePath}" }
}
}
if (fetchCover) {
commandArray.add("-c")
commandArray.add(targetCover.absolutePath)
Expand Down

0 comments on commit b1482e1

Please sign in to comment.