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