mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Fix/losing downloads on manga rename during update (#2051)
* Fix renaming manga download dir * Simplify manga download dir rename function --------- Co-authored-by: Mitchell Syer <Syer10@users.noreply.github.com>
This commit is contained in:
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|||||||
- (**WebUI**) Handle serving non-default webui with "bundled"
|
- (**WebUI**) Handle serving non-default webui with "bundled"
|
||||||
- (**WebUI**) Wait until WebUI is ready to open in browser
|
- (**WebUI**) Wait until WebUI is ready to open in browser
|
||||||
- (**Downloads**) Truncate filenames by byte length to prevent "File name too long" IO errors
|
- (**Downloads**) Truncate filenames by byte length to prevent "File name too long" IO errors
|
||||||
|
- (**Downloads**) Fix being unable to find downloads after manga was renamed during an update
|
||||||
- (**Downloads**) Fix preserving chapter download states during an update
|
- (**Downloads**) Fix preserving chapter download states during an update
|
||||||
- (**Extension**) Do not indicate an update is available when the extension is not installed
|
- (**Extension**) Do not indicate an update is available when the extension is not installed
|
||||||
- (**Chapter**) Fix losing chapter data on failed chapter list update
|
- (**Chapter**) Fix losing chapter data on failed chapter list update
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ object Manga {
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
if (remoteTitle.isNotEmpty() && remoteTitle != mangaEntry[MangaTable.title]) {
|
if (remoteTitle.isNotEmpty() && remoteTitle != mangaEntry[MangaTable.title]) {
|
||||||
val canUpdateTitle = updateMangaDownloadDir(mangaId, remoteTitle)
|
val canUpdateTitle = updateMangaDownloadDir(mangaEntry[MangaTable.title], source.toString(), remoteTitle)
|
||||||
|
|
||||||
if (canUpdateTitle) {
|
if (canUpdateTitle) {
|
||||||
it[MangaTable.title] = remoteTitle
|
it[MangaTable.title] = remoteTitle
|
||||||
|
|||||||
@@ -24,14 +24,22 @@ private val applicationDirs: ApplicationDirs by injectLazy()
|
|||||||
|
|
||||||
private val logger = KotlinLogging.logger { }
|
private val logger = KotlinLogging.logger { }
|
||||||
|
|
||||||
|
private fun getMangaDir(
|
||||||
|
title: String,
|
||||||
|
sourceName: String,
|
||||||
|
): String {
|
||||||
|
val sourceDir = SafePath.buildValidFilename(sourceName)
|
||||||
|
val mangaDir = SafePath.buildValidFilename(title)
|
||||||
|
|
||||||
|
return "$sourceDir/$mangaDir"
|
||||||
|
}
|
||||||
|
|
||||||
private fun getMangaDir(mangaId: Int): String =
|
private fun getMangaDir(mangaId: Int): String =
|
||||||
transaction {
|
transaction {
|
||||||
val mangaEntry = MangaTable.selectAll().where { MangaTable.id eq mangaId }.first()
|
val mangaEntry = MangaTable.selectAll().where { MangaTable.id eq mangaId }.first()
|
||||||
val source = GetCatalogueSource.getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
val source = GetCatalogueSource.getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
||||||
|
|
||||||
val sourceDir = SafePath.buildValidFilename(source.toString())
|
getMangaDir(mangaEntry[MangaTable.title], source.toString())
|
||||||
val mangaDir = SafePath.buildValidFilename(mangaEntry[MangaTable.title])
|
|
||||||
"$sourceDir/$mangaDir"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getChapterDir(
|
private fun getChapterDir(
|
||||||
@@ -62,6 +70,11 @@ private fun getChapterDir(
|
|||||||
|
|
||||||
fun getThumbnailDownloadPath(mangaId: Int): String = applicationDirs.thumbnailDownloadsRoot + "/$mangaId"
|
fun getThumbnailDownloadPath(mangaId: Int): String = applicationDirs.thumbnailDownloadsRoot + "/$mangaId"
|
||||||
|
|
||||||
|
fun getMangaDownloadDir(
|
||||||
|
title: String,
|
||||||
|
sourceName: String,
|
||||||
|
): String = applicationDirs.mangaDownloadsRoot + "/" + getMangaDir(title, sourceName)
|
||||||
|
|
||||||
fun getMangaDownloadDir(mangaId: Int): String = applicationDirs.mangaDownloadsRoot + "/" + getMangaDir(mangaId)
|
fun getMangaDownloadDir(mangaId: Int): String = applicationDirs.mangaDownloadsRoot + "/" + getMangaDir(mangaId)
|
||||||
|
|
||||||
fun getChapterDownloadPath(
|
fun getChapterDownloadPath(
|
||||||
@@ -81,24 +94,12 @@ fun getChapterCachePath(
|
|||||||
|
|
||||||
/** return value says if rename/move was successful */
|
/** return value says if rename/move was successful */
|
||||||
fun updateMangaDownloadDir(
|
fun updateMangaDownloadDir(
|
||||||
mangaId: Int,
|
title: String,
|
||||||
|
sourceName: String,
|
||||||
newTitle: String,
|
newTitle: String,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
// Get current manga directory (uses its own transaction)
|
val oldDir = getMangaDownloadDir(title, sourceName)
|
||||||
val currentMangaDir = getMangaDir(mangaId)
|
val newDir = getMangaDownloadDir(newTitle, sourceName)
|
||||||
|
|
||||||
// Build new directory path
|
|
||||||
val newMangaDir =
|
|
||||||
transaction {
|
|
||||||
val mangaEntry = MangaTable.selectAll().where { MangaTable.id eq mangaId }.first()
|
|
||||||
val source = GetCatalogueSource.getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
|
||||||
val sourceDir = SafePath.buildValidFilename(source.toString())
|
|
||||||
val newMangaDirName = SafePath.buildValidFilename(newTitle)
|
|
||||||
"$sourceDir/$newMangaDirName"
|
|
||||||
}
|
|
||||||
|
|
||||||
val oldDir = "${applicationDirs.downloadsRoot}/$currentMangaDir"
|
|
||||||
val newDir = "${applicationDirs.downloadsRoot}/$newMangaDir"
|
|
||||||
|
|
||||||
val oldDirFile = File(oldDir)
|
val oldDirFile = File(oldDir)
|
||||||
val newDirFile = File(newDir)
|
val newDirFile = File(newDir)
|
||||||
|
|||||||
Reference in New Issue
Block a user