mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
Try to keep cached images usable on manga rename (#2052)
This commit is contained in:
@@ -77,6 +77,11 @@ fun getMangaDownloadDir(
|
|||||||
|
|
||||||
fun getMangaDownloadDir(mangaId: Int): String = applicationDirs.mangaDownloadsRoot + "/" + getMangaDir(mangaId)
|
fun getMangaDownloadDir(mangaId: Int): String = applicationDirs.mangaDownloadsRoot + "/" + getMangaDir(mangaId)
|
||||||
|
|
||||||
|
fun getMangaCacheDir(
|
||||||
|
title: String,
|
||||||
|
sourceName: String,
|
||||||
|
): String = applicationDirs.tempMangaCacheRoot + "/" + getMangaDir(title, sourceName)
|
||||||
|
|
||||||
fun getChapterDownloadPath(
|
fun getChapterDownloadPath(
|
||||||
mangaId: Int,
|
mangaId: Int,
|
||||||
chapterId: Int,
|
chapterId: Int,
|
||||||
@@ -92,26 +97,21 @@ fun getChapterCachePath(
|
|||||||
chapterId: Int,
|
chapterId: Int,
|
||||||
): String = applicationDirs.tempMangaCacheRoot + "/" + getChapterDir(mangaId, chapterId)
|
): String = applicationDirs.tempMangaCacheRoot + "/" + getChapterDir(mangaId, chapterId)
|
||||||
|
|
||||||
/** return value says if rename/move was successful */
|
private fun updateDownloadDir(
|
||||||
fun updateMangaDownloadDir(
|
currentDir: String,
|
||||||
title: String,
|
newDir: String,
|
||||||
sourceName: String,
|
|
||||||
newTitle: String,
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val oldDir = getMangaDownloadDir(title, sourceName)
|
val currentDirFile = File(currentDir)
|
||||||
val newDir = getMangaDownloadDir(newTitle, sourceName)
|
|
||||||
|
|
||||||
val oldDirFile = File(oldDir)
|
|
||||||
val newDirFile = File(newDir)
|
val newDirFile = File(newDir)
|
||||||
|
|
||||||
if (!oldDirFile.exists()) {
|
if (!currentDirFile.exists()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
Files.move(oldDirFile.toPath(), newDirFile.toPath())
|
Files.move(currentDirFile.toPath(), newDirFile.toPath())
|
||||||
|
|
||||||
if (oldDirFile.exists()) {
|
if (currentDirFile.exists()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +119,31 @@ fun updateMangaDownloadDir(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
return true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.error(e) { "updateMangaDownloadDir: failed to rename manga download folder from \"$oldDir\" to \"$newDir\"" }
|
logger.error(e) { "updateDownloadDir: failed to rename download folder from \"$currentDir\" to \"$newDir\"" }
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** return value says if rename/move was successful */
|
||||||
|
fun updateMangaDownloadDir(
|
||||||
|
title: String,
|
||||||
|
sourceName: String,
|
||||||
|
newTitle: String,
|
||||||
|
): Boolean {
|
||||||
|
val currentDownloadDir = getMangaDownloadDir(title, sourceName)
|
||||||
|
val newDownloadDir = getMangaDownloadDir(newTitle, sourceName)
|
||||||
|
|
||||||
|
val renamed = updateDownloadDir(currentDownloadDir, newDownloadDir)
|
||||||
|
|
||||||
|
val tryToKeepCachedFilesUsable = renamed
|
||||||
|
if (tryToKeepCachedFilesUsable) {
|
||||||
|
val currentCacheDir = getMangaCacheDir(title, sourceName)
|
||||||
|
val newCacheDir = getMangaCacheDir(newTitle, sourceName)
|
||||||
|
|
||||||
|
updateDownloadDir(currentCacheDir, newCacheDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
return renamed
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user