Implement clearing full backup data from storage
This commit is contained in:
parent
1ee443a3d8
commit
a6e971609c
4 changed files with 18 additions and 8 deletions
|
@ -152,7 +152,7 @@ class FullBackup(
|
|||
}
|
||||
|
||||
fun clearBackupData(packageInfo: PackageInfo) {
|
||||
// TODO
|
||||
plugin.removeDataOfPackage(packageInfo)
|
||||
}
|
||||
|
||||
fun cancelFullBackup() {
|
||||
|
@ -160,7 +160,7 @@ class FullBackup(
|
|||
val state = this.state ?: throw AssertionError("No state when canceling")
|
||||
clearState()
|
||||
try {
|
||||
plugin.cancelFullBackup(state.packageInfo)
|
||||
plugin.removeDataOfPackage(state.packageInfo)
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, "Error cancelling full backup for ${state.packageName}", e)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,10 @@ interface FullBackupPlugin {
|
|||
@Throws(IOException::class)
|
||||
fun getOutputStream(targetPackage: PackageInfo): OutputStream
|
||||
|
||||
/**
|
||||
* Remove all data associated with the given package.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun cancelFullBackup(targetPackage: PackageInfo)
|
||||
fun removeDataOfPackage(packageInfo: PackageInfo)
|
||||
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ class DocumentsProviderFullBackup(
|
|||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun cancelFullBackup(targetPackage: PackageInfo) {
|
||||
val packageName = targetPackage.packageName
|
||||
Log.i(TAG, "Deleting $packageName due to canceled backup...")
|
||||
override fun removeDataOfPackage(packageInfo: PackageInfo) {
|
||||
val packageName = packageInfo.packageName
|
||||
Log.i(TAG, "Deleting $packageName...")
|
||||
val file = storage.defaultFullBackupDir?.findFile(packageName) ?: return
|
||||
if (!file.delete()) throw IOException("Failed to delete $packageName")
|
||||
}
|
||||
|
|
|
@ -174,11 +174,18 @@ internal class FullBackupTest : BackupTest() {
|
|||
assertFalse(backup.hasState())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clearBackupData delegates to plugin`() {
|
||||
every { plugin.removeDataOfPackage(packageInfo) } just Runs
|
||||
|
||||
backup.clearBackupData(packageInfo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cancel full backup runs ok`() {
|
||||
expectPerformFullBackup()
|
||||
expectClearState()
|
||||
every { plugin.cancelFullBackup(packageInfo) } just Runs
|
||||
every { plugin.removeDataOfPackage(packageInfo) } just Runs
|
||||
|
||||
assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
|
||||
assertTrue(backup.hasState())
|
||||
|
@ -190,7 +197,7 @@ internal class FullBackupTest : BackupTest() {
|
|||
fun `cancel full backup ignores exception when calling plugin`() {
|
||||
expectPerformFullBackup()
|
||||
expectClearState()
|
||||
every { plugin.cancelFullBackup(packageInfo) } throws IOException()
|
||||
every { plugin.removeDataOfPackage(packageInfo) } throws IOException()
|
||||
|
||||
assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
|
||||
assertTrue(backup.hasState())
|
||||
|
|
Loading…
Reference in a new issue