mirror of
https://github.com/gotson/komga.git
synced 2026-05-07 12:01:40 +02:00
fix: soft delete after deleting files instead of triggering a scan
This commit is contained in:
parent
b53fbc7217
commit
dabe398274
3 changed files with 19 additions and 19 deletions
|
|
@ -141,14 +141,12 @@ class TaskHandler(
|
||||||
is Task.DeleteBook -> {
|
is Task.DeleteBook -> {
|
||||||
bookRepository.findByIdOrNull(task.bookId)?.let { book ->
|
bookRepository.findByIdOrNull(task.bookId)?.let { book ->
|
||||||
bookLifecycle.deleteBookFiles(book)
|
bookLifecycle.deleteBookFiles(book)
|
||||||
taskReceiver.scanLibrary(book.libraryId, task.priority)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is Task.DeleteSeries -> {
|
is Task.DeleteSeries -> {
|
||||||
seriesRepository.findByIdOrNull(task.seriesId)?.let { series ->
|
seriesRepository.findByIdOrNull(task.seriesId)?.let { series ->
|
||||||
seriesLifecycle.deleteSeriesFiles(series)
|
seriesLifecycle.deleteSeriesFiles(series)
|
||||||
taskReceiver.scanLibrary(series.libraryId, task.priority)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import org.gotson.komga.domain.model.Media
|
||||||
import org.gotson.komga.domain.model.MediaNotReadyException
|
import org.gotson.komga.domain.model.MediaNotReadyException
|
||||||
import org.gotson.komga.domain.model.ReadProgress
|
import org.gotson.komga.domain.model.ReadProgress
|
||||||
import org.gotson.komga.domain.model.ThumbnailBook
|
import org.gotson.komga.domain.model.ThumbnailBook
|
||||||
import org.gotson.komga.domain.model.withCode
|
|
||||||
import org.gotson.komga.domain.persistence.BookMetadataRepository
|
import org.gotson.komga.domain.persistence.BookMetadataRepository
|
||||||
import org.gotson.komga.domain.persistence.BookRepository
|
import org.gotson.komga.domain.persistence.BookRepository
|
||||||
import org.gotson.komga.domain.persistence.LibraryRepository
|
import org.gotson.komga.domain.persistence.LibraryRepository
|
||||||
|
|
@ -27,9 +26,7 @@ import org.gotson.komga.infrastructure.image.ImageType
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.support.TransactionTemplate
|
import org.springframework.transaction.support.TransactionTemplate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileNotFoundException
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import kotlin.io.path.deleteExisting
|
|
||||||
import kotlin.io.path.deleteIfExists
|
import kotlin.io.path.deleteIfExists
|
||||||
import kotlin.io.path.exists
|
import kotlin.io.path.exists
|
||||||
import kotlin.io.path.isWritable
|
import kotlin.io.path.isWritable
|
||||||
|
|
@ -323,17 +320,21 @@ class BookLifecycle(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteBookFiles(book: Book) {
|
fun deleteBookFiles(book: Book) {
|
||||||
if (book.path.notExists() || !book.path.isWritable())
|
if (book.path.notExists()) return logger.info { "Cannot delete book file, path does not exist: ${book.path}" }
|
||||||
throw FileNotFoundException("File is not accessible : ${book.path}").withCode("ERR_1018")
|
if (!book.path.isWritable()) return logger.info { "Cannot delete book file, path is not writable: ${book.path}" }
|
||||||
|
|
||||||
val thumbnails = thumbnailBookRepository.findAllByBookIdAndType(book.id, ThumbnailBook.Type.SIDECAR)
|
val thumbnails = thumbnailBookRepository.findAllByBookIdAndType(book.id, ThumbnailBook.Type.SIDECAR)
|
||||||
.mapNotNull { it.url?.toURI()?.toPath() }
|
.mapNotNull { it.url?.toURI()?.toPath() }
|
||||||
.filter { it.exists() && it.isWritable() }
|
.filter { it.exists() && it.isWritable() }
|
||||||
|
|
||||||
book.path.deleteIfExists()
|
if (book.path.deleteIfExists()) logger.info { "Deleted file: ${book.path}" }
|
||||||
thumbnails.forEach { it.deleteIfExists() }
|
thumbnails.forEach {
|
||||||
|
if (it.deleteIfExists()) logger.info { "Deleted file: $it" }
|
||||||
|
}
|
||||||
|
|
||||||
if (book.path.parent.listDirectoryEntries().isEmpty())
|
if (book.path.parent.listDirectoryEntries().isEmpty())
|
||||||
book.path.parent.deleteExisting()
|
if (book.path.parent.deleteIfExists()) logger.info { "Deleted directory: ${book.path.parent}" }
|
||||||
|
|
||||||
|
softDeleteMany(listOf(book))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import org.gotson.komga.domain.model.ReadProgress
|
||||||
import org.gotson.komga.domain.model.Series
|
import org.gotson.komga.domain.model.Series
|
||||||
import org.gotson.komga.domain.model.SeriesMetadata
|
import org.gotson.komga.domain.model.SeriesMetadata
|
||||||
import org.gotson.komga.domain.model.ThumbnailSeries
|
import org.gotson.komga.domain.model.ThumbnailSeries
|
||||||
import org.gotson.komga.domain.model.withCode
|
|
||||||
import org.gotson.komga.domain.persistence.BookMetadataAggregationRepository
|
import org.gotson.komga.domain.persistence.BookMetadataAggregationRepository
|
||||||
import org.gotson.komga.domain.persistence.BookMetadataRepository
|
import org.gotson.komga.domain.persistence.BookMetadataRepository
|
||||||
import org.gotson.komga.domain.persistence.BookRepository
|
import org.gotson.komga.domain.persistence.BookRepository
|
||||||
|
|
@ -33,8 +32,6 @@ import org.gotson.komga.infrastructure.language.stripAccents
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.support.TransactionTemplate
|
import org.springframework.transaction.support.TransactionTemplate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileNotFoundException
|
|
||||||
import java.nio.file.Path
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import kotlin.io.path.deleteIfExists
|
import kotlin.io.path.deleteIfExists
|
||||||
import kotlin.io.path.exists
|
import kotlin.io.path.exists
|
||||||
|
|
@ -96,8 +93,8 @@ class SeriesLifecycle(
|
||||||
book, metadata,
|
book, metadata,
|
||||||
metadata.copy(
|
metadata.copy(
|
||||||
number = if (!metadata.numberLock) (index + 1).toString() else metadata.number,
|
number = if (!metadata.numberLock) (index + 1).toString() else metadata.number,
|
||||||
numberSort = if (!metadata.numberSortLock) (index + 1).toFloat() else metadata.numberSort
|
numberSort = if (!metadata.numberSortLock) (index + 1).toFloat() else metadata.numberSort,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
bookMetadataRepository.update(oldToNew.map { it.third })
|
bookMetadataRepository.update(oldToNew.map { it.third })
|
||||||
|
|
@ -294,8 +291,8 @@ class SeriesLifecycle(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteSeriesFiles(series: Series) {
|
fun deleteSeriesFiles(series: Series) {
|
||||||
if (series.path.notExists() || !series.path.isWritable())
|
if (series.path.notExists()) return logger.info { "Cannot delete series folder, path does not exist: ${series.path}" }
|
||||||
throw FileNotFoundException("File is not accessible : ${series.path}").withCode("ERR_1018")
|
if (!series.path.isWritable()) return logger.info { "Cannot delete series folder, path is not writable: ${series.path}" }
|
||||||
|
|
||||||
val thumbnails = thumbnailsSeriesRepository.findAllBySeriesIdIdAndType(series.id, ThumbnailSeries.Type.SIDECAR)
|
val thumbnails = thumbnailsSeriesRepository.findAllBySeriesIdIdAndType(series.id, ThumbnailSeries.Type.SIDECAR)
|
||||||
.mapNotNull { it.url?.toURI()?.toPath() }
|
.mapNotNull { it.url?.toURI()?.toPath() }
|
||||||
|
|
@ -303,10 +300,14 @@ class SeriesLifecycle(
|
||||||
|
|
||||||
bookRepository.findAllBySeriesId(series.id)
|
bookRepository.findAllBySeriesId(series.id)
|
||||||
.forEach { bookLifecycle.deleteBookFiles(it) }
|
.forEach { bookLifecycle.deleteBookFiles(it) }
|
||||||
thumbnails.forEach(Path::deleteIfExists)
|
thumbnails.forEach {
|
||||||
|
if (it.deleteIfExists()) logger.info { "Deleted file: $it" }
|
||||||
|
}
|
||||||
|
|
||||||
if (series.path.exists() && series.path.listDirectoryEntries().isEmpty())
|
if (series.path.exists() && series.path.listDirectoryEntries().isEmpty())
|
||||||
series.path.deleteIfExists()
|
if (series.path.deleteIfExists()) logger.info { "Deleted directory: ${series.path}" }
|
||||||
|
|
||||||
|
softDeleteMany(listOf(series))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun thumbnailsHouseKeeping(seriesId: String) {
|
private fun thumbnailsHouseKeeping(seriesId: String) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue