Allow overwrite non-empty download directory #99

pull/102/head
Koitharu 4 years ago
parent c218ae0baa
commit 7ebb98ce06
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -16,7 +16,7 @@ class MangaZip(val file: File) {
private var index = MangaIndex(null)
suspend fun prepare(manga: Manga) {
writableCbz.prepare()
writableCbz.prepare(overwrite = true)
index = MangaIndex(writableCbz[INDEX_ENTRY].takeIfReadable()?.readText())
index.setMangaInfo(manga, append = true)
}

@ -14,9 +14,13 @@ class WritableCbzFile(private val file: File) {
private val dir = File(file.parentFile, file.nameWithoutExtension)
suspend fun prepare() = withContext(Dispatchers.IO) {
check(dir.list().isNullOrEmpty()) {
"Dir ${dir.name} is not empty"
suspend fun prepare(overwrite: Boolean) = withContext(Dispatchers.IO) {
if (!dir.list().isNullOrEmpty()) {
if (overwrite) {
dir.deleteRecursively()
} else {
throw IllegalStateException("Dir ${dir.name} is not empty")
}
}
if (!dir.exists()) {
dir.mkdir()

Loading…
Cancel
Save