Close K/V DB after restoring records
also don't log stack trace when not finding backup type
This commit is contained in:
parent
ef5d1c3bc8
commit
79777a7b6f
4 changed files with 31 additions and 17 deletions
|
@ -64,13 +64,12 @@ class KvDbManagerImpl(private val context: Context) : KvDbManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KVDb {
|
interface KVDb : AutoCloseable {
|
||||||
fun put(key: String, value: ByteArray)
|
fun put(key: String, value: ByteArray)
|
||||||
fun get(key: String): ByteArray?
|
fun get(key: String): ByteArray?
|
||||||
fun getAll(): List<Pair<String, ByteArray>>
|
fun getAll(): List<Pair<String, ByteArray>>
|
||||||
fun delete(key: String)
|
fun delete(key: String)
|
||||||
fun vacuum()
|
fun vacuum()
|
||||||
fun close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class KVDbImpl(context: Context, fileName: String) :
|
class KVDbImpl(context: Context, fileName: String) :
|
||||||
|
|
|
@ -98,7 +98,12 @@ internal class KVRestore(
|
||||||
val isAutoRestore = state.packageInfo.packageName == MAGIC_PACKAGE_MANAGER &&
|
val isAutoRestore = state.packageInfo.packageName == MAGIC_PACKAGE_MANAGER &&
|
||||||
pmPackageName != null
|
pmPackageName != null
|
||||||
return try {
|
return try {
|
||||||
val db = if (isAutoRestore) getCachedRestoreDb(state) else downloadRestoreDb(state)
|
val database = if (isAutoRestore) {
|
||||||
|
getCachedRestoreDb(state)
|
||||||
|
} else {
|
||||||
|
downloadRestoreDb(state)
|
||||||
|
}
|
||||||
|
database.use { db ->
|
||||||
val out = outputFactory.getBackupDataOutput(data)
|
val out = outputFactory.getBackupDataOutput(data)
|
||||||
val records = if (isAutoRestore) {
|
val records = if (isAutoRestore) {
|
||||||
val keys = listOf(ANCESTRAL_RECORD_KEY, GLOBAL_METADATA_KEY, pmPackageName)
|
val keys = listOf(ANCESTRAL_RECORD_KEY, GLOBAL_METADATA_KEY, pmPackageName)
|
||||||
|
@ -113,6 +118,7 @@ internal class KVRestore(
|
||||||
out.writeEntityHeader(key, size)
|
out.writeEntityHeader(key, size)
|
||||||
out.writeEntityData(value, size)
|
out.writeEntityData(value, size)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
TRANSPORT_OK
|
TRANSPORT_OK
|
||||||
} catch (e: UnsupportedVersionException) {
|
} catch (e: UnsupportedVersionException) {
|
||||||
Log.e(TAG, "Unsupported version in backup: ${e.version}", e)
|
Log.e(TAG, "Unsupported version in backup: ${e.version}", e)
|
||||||
|
|
|
@ -225,9 +225,16 @@ internal class RestoreCoordinator(
|
||||||
full.initializeState(version, state.token, name, packageInfo)
|
full.initializeState(version, state.token, name, packageInfo)
|
||||||
state.currentPackage = packageName
|
state.currentPackage = packageName
|
||||||
TYPE_FULL_STREAM
|
TYPE_FULL_STREAM
|
||||||
} else throw IOException("No data found for $packageName. Skipping.")
|
} else throw IOException("No data found for $packageName. Skipping...")
|
||||||
|
}
|
||||||
|
null -> {
|
||||||
|
Log.i(TAG, "No backup type found for $packageName. Skipping...")
|
||||||
|
state.backupMetadata.packageMetadataMap[packageName]?.backupType?.let { s ->
|
||||||
|
Log.w(TAG, "State was ${s.name}")
|
||||||
|
}
|
||||||
|
failedPackages.add(packageName)
|
||||||
|
return nextRestorePackage()
|
||||||
}
|
}
|
||||||
null -> throw IOException("No backup type found for $packageName. Skipping.")
|
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "Error finding restore data for $packageName.", e)
|
Log.e(TAG, "Error finding restore data for $packageName.", e)
|
||||||
|
|
|
@ -11,9 +11,9 @@ import com.stevesoltys.seedvault.header.VERSION
|
||||||
import com.stevesoltys.seedvault.header.VersionHeader
|
import com.stevesoltys.seedvault.header.VersionHeader
|
||||||
import com.stevesoltys.seedvault.header.getADForKV
|
import com.stevesoltys.seedvault.header.getADForKV
|
||||||
import com.stevesoltys.seedvault.plugins.LegacyStoragePlugin
|
import com.stevesoltys.seedvault.plugins.LegacyStoragePlugin
|
||||||
|
import com.stevesoltys.seedvault.plugins.StoragePlugin
|
||||||
import com.stevesoltys.seedvault.transport.backup.KVDb
|
import com.stevesoltys.seedvault.transport.backup.KVDb
|
||||||
import com.stevesoltys.seedvault.transport.backup.KvDbManager
|
import com.stevesoltys.seedvault.transport.backup.KvDbManager
|
||||||
import com.stevesoltys.seedvault.plugins.StoragePlugin
|
|
||||||
import io.mockk.Runs
|
import io.mockk.Runs
|
||||||
import io.mockk.coEvery
|
import io.mockk.coEvery
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
|
@ -148,6 +148,7 @@ internal class KVRestoreTest : RestoreTest() {
|
||||||
every { output.writeEntityHeader(key2, data2.size) } returns 42
|
every { output.writeEntityHeader(key2, data2.size) } returns 42
|
||||||
every { output.writeEntityData(data2, data2.size) } returns data2.size
|
every { output.writeEntityData(data2, data2.size) } returns data2.size
|
||||||
|
|
||||||
|
every { db.close() } just Runs
|
||||||
every { dbManager.deleteDb(packageInfo.packageName, true) } returns true
|
every { dbManager.deleteDb(packageInfo.packageName, true) } returns true
|
||||||
streamsGetClosed()
|
streamsGetClosed()
|
||||||
|
|
||||||
|
@ -159,6 +160,7 @@ internal class KVRestoreTest : RestoreTest() {
|
||||||
output.writeEntityData(data, data.size)
|
output.writeEntityData(data, data.size)
|
||||||
output.writeEntityHeader(key2, data2.size)
|
output.writeEntityHeader(key2, data2.size)
|
||||||
output.writeEntityData(data2, data2.size)
|
output.writeEntityData(data2, data2.size)
|
||||||
|
db.close()
|
||||||
dbManager.deleteDb(packageInfo.packageName, true)
|
dbManager.deleteDb(packageInfo.packageName, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue