From 17d0885e777cc4bb99369e7efcf4dc70affdc8ff Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 5 Sep 2024 09:11:52 -0300 Subject: [PATCH] Fix retries: don't upload metadata three times --- .../java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt | 1 + .../com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt index a36eafe7..0e5d48d6 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt @@ -135,6 +135,7 @@ internal class ApkBackupManager( for (i in 1..n) { try { block() + return } catch (e: Exception) { if (i == n) throw e Log.e(TAG, "Error (#$i), we'll keep trying", e) diff --git a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt index 5a7652eb..5dafa04b 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt @@ -234,6 +234,10 @@ internal class ApkBackupManagerTest : TransportTest() { apkBackup.backupApkIfNecessary(notAllowedPackages[1], any()) metadataOutputStream.close() } + // metadata should only get uploaded once + verify(exactly = 1) { + metadataManager.uploadMetadata(metadataOutputStream) + } } @Test