Limit saved page filenames to 127 characters (fixes #2638)

This commit is contained in:
arkon 2020-03-04 22:33:16 -05:00
parent 8ae15141f6
commit 6940ad3fd9

View File

@ -448,9 +448,10 @@ class ReaderPresenter(
val chapter = page.chapter.chapter val chapter = page.chapter.chapter
// Build destination file. // Build destination file.
val filenameSuffix = " - ${page.number}.${type.extension}"
val filename = DiskUtil.buildValidFilename( val filename = DiskUtil.buildValidFilename(
"${manga.title} - ${chapter.name}".take(225) "${manga.title} - ${chapter.name}".take(MAX_FILE_NAME_LENGTH - filenameSuffix.length)
) + " - ${page.number}.${type.extension}" ) + filenameSuffix
val destFile = File(directory, filename) val destFile = File(directory, filename)
stream().use { input -> stream().use { input ->
@ -638,4 +639,9 @@ class ReaderPresenter(
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.subscribe() .subscribe()
} }
companion object {
// Safe max filename size is 255 bytes and 1 char = 2 bytes
private const val MAX_FILE_NAME_LENGTH = 127
}
} }