diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt index 0b59917c9..40ff0723c 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt @@ -147,7 +147,7 @@ class LibraryContentLifecycle( existingBooks.find { it.url == newBook.url && it.deletedDate == null }?.let { existingBook -> logger.debug { "Matched existing book: $existingBook" } if (newBook.fileLastModified.notEquals(existingBook.fileLastModified)) { - val hash = if (existingBook.fileHash.isNotBlank()) { + val hash = if (existingBook.fileSize == newBook.fileSize && existingBook.fileHash.isNotBlank()) { hasher.computeHash(newBook.path) } else null if (hash == existingBook.fileHash) { diff --git a/komga/src/test/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycleTest.kt b/komga/src/test/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycleTest.kt index 496bfc91b..1517a317f 100644 --- a/komga/src/test/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycleTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycleTest.kt @@ -208,6 +208,44 @@ class LibraryContentLifecycleTest( assertThat(media.status).isEqualTo(Media.Status.OUTDATED) } + @Test + fun `given existing series when scanning and updated files have a different size then books are marked outdated`() { + // given + val library = makeLibrary() + libraryRepository.insert(library) + + every { mockScanner.scanRootFolder(any()) } + .returnsMany( + mapOf(makeSeries(name = "series") to listOf(makeBook("book1").copy(fileSize = 1))).toScanResult(), + mapOf(makeSeries(name = "series") to listOf(makeBook("book1").copy(fileSize = 2))).toScanResult(), + ) + libraryContentLifecycle.scanRootFolder(library) + + bookRepository.findAll().first().let { book -> + bookRepository.update(book.copy(fileHash = "hashed")) + mediaRepository.update(mediaRepository.findById(book.id).copy(status = Media.Status.READY)) + } + + // when + libraryContentLifecycle.scanRootFolder(library) + + // then + val allSeries = seriesRepository.findAll() + val allBooks = bookRepository.findAll() + + verify(exactly = 2) { mockScanner.scanRootFolder(any()) } + verify(exactly = 0) { mockHasher.computeHash(any()) } + + assertThat(allSeries).hasSize(1) + assertThat(allBooks).hasSize(1) + val book = allBooks.first() + assertThat(book.name).isEqualTo("book1") + assertThat(book.lastModifiedDate).isNotEqualTo(book.createdDate) + assertThat(book.fileHash).isBlank + val media = mediaRepository.findById(book.id) + assertThat(media.status).isEqualTo(Media.Status.OUTDATED) + } + @Test fun `given existing series when scanning and updated files have the same hash then books are not marked outdated`() { // given