Merge pull request #1378 from kiwix/feature/macgills/#1376-delete-zims

#1376 Unable to delete old zim files after re-install
This commit is contained in:
Seán Mac Gillicuddy 2019-08-15 14:51:06 +01:00 committed by GitHub
commit 13cb6ffd52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,8 @@ import javax.inject.Inject
class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
fun books() = box.asFlowable()
.doOnNext(::removeBooksThatDoNotExist)
.map { books -> books.filter { it.file.exists() } }
.map { it.map(::BookOnDisk) }
fun getBooks() = box.all.map(::BookOnDisk)
@ -52,4 +54,12 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
fun migrationInsert(books: ArrayList<Book>) {
insert(books.map { BookOnDisk(book = it, file = it.file) })
}
private fun removeBooksThatDoNotExist(books: MutableList<BookOnDiskEntity>) {
delete(books.filterNot { it.file.exists() })
}
private fun delete(books: List<BookOnDiskEntity>) {
box.remove(books)
}
}