diff --git a/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackup.kt b/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackup.kt index 0a56c59b..ec2746d5 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackup.kt +++ b/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackup.kt @@ -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) } diff --git a/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackupPlugin.kt b/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackupPlugin.kt index c1f1a3f0..0e0ee772 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackupPlugin.kt +++ b/app/src/main/java/com/stevesoltys/backup/transport/backup/FullBackupPlugin.kt @@ -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) } diff --git a/app/src/main/java/com/stevesoltys/backup/transport/backup/plugins/DocumentsProviderFullBackup.kt b/app/src/main/java/com/stevesoltys/backup/transport/backup/plugins/DocumentsProviderFullBackup.kt index 2116b926..b6540fa9 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/backup/plugins/DocumentsProviderFullBackup.kt +++ b/app/src/main/java/com/stevesoltys/backup/transport/backup/plugins/DocumentsProviderFullBackup.kt @@ -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") } diff --git a/app/src/test/java/com/stevesoltys/backup/transport/backup/FullBackupTest.kt b/app/src/test/java/com/stevesoltys/backup/transport/backup/FullBackupTest.kt index b6f1972e..af66c82b 100644 --- a/app/src/test/java/com/stevesoltys/backup/transport/backup/FullBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/backup/transport/backup/FullBackupTest.kt @@ -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())