Fix database export
This commit is contained in:
1 parent
30fc750e17
commit
8cc531ccec
2 files changed
+8
-3
No files matched your search
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.hippo.ehviewer
|
package com.hippo.ehviewer
|
||||||
|
|
||||||
|
import androidx.room.execSQL
|
||||||
|
import androidx.room.useWriterConnection
|
||||||
import arrow.fx.coroutines.resource
|
import arrow.fx.coroutines.resource
|
||||||
import arrow.fx.coroutines.resourceScope
|
import arrow.fx.coroutines.resourceScope
|
||||||
import com.ehviewer.core.data.model.asEntity
|
import com.ehviewer.core.data.model.asEntity
|
||||||
@@ -276,8 +278,11 @@ object EhDB {
|
|||||||
db.filterDao().update(filter)
|
db.filterDao().update(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportDB(file: Path) {
|
suspend fun exportDB(file: Path) {
|
||||||
db.query("PRAGMA wal_checkpoint(FULL)", null).use { it.moveToNext() }
|
db.useWriterConnection { conn ->
|
||||||
|
conn.execSQL("PRAGMA wal_checkpoint(FULL)")
|
||||||
|
conn.execSQL("VACUUM")
|
||||||
|
}
|
||||||
val dbFile = getDatabasePath(DB_NAME)
|
val dbFile = getDatabasePath(DB_NAME)
|
||||||
dbFile sendTo file
|
dbFile sendTo file
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ private fun dumplog(uri: Uri): Unit = with(ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context(ctx: Context)
|
context(ctx: Context)
|
||||||
private fun exportDatabase(uri: Uri) {
|
private suspend fun exportDatabase(uri: Uri) {
|
||||||
ctx.grantUriPermission(BuildConfig.APPLICATION_ID, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
ctx.grantUriPermission(BuildConfig.APPLICATION_ID, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
EhDB.exportDB(uri.toOkioPath())
|
EhDB.exportDB(uri.toOkioPath())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user