Skip to content

Commit

Permalink
Remove known bad blobs from do-not-use list when deleting them
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Nov 8, 2024
1 parent 69765c7 commit ae77ebe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 11 additions & 4 deletions app/src/main/java/com/stevesoltys/seedvault/repo/Pruner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class Pruner(
private val crypto: Crypto,
private val backendManager: BackendManager,
private val snapshotManager: SnapshotManager,
private val blobCache: BlobCache,
) {

private val log = KotlinLogging.logger {}
Expand Down Expand Up @@ -77,11 +78,17 @@ internal class Pruner(
blob.id.hexFromProto()
}
}.toSet()
blobHandles.forEach { blobHandle ->
if (blobHandle.name !in usedBlobIds) {
log.info { "Removing blob ${blobHandle.name}" }
backendManager.backend.remove(blobHandle)
val removedBlobs = mutableSetOf<String>()
try {
blobHandles.forEach { blobHandle ->
if (blobHandle.name !in usedBlobIds) {
log.info { "Removing blob ${blobHandle.name}" }
backendManager.backend.remove(blobHandle)
removedBlobs.add(blobHandle.name)
}
}
} finally {
if (removedBlobs.isNotEmpty()) blobCache.onBlobsRemoved(removedBlobs)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ internal class PrunerTest : TransportTest() {

private val backendManager: BackendManager = mockk()
private val snapshotManager: SnapshotManager = mockk()
private val blobCache: BlobCache = mockk()
private val backend: Backend = mockk()

private val pruner = Pruner(crypto, backendManager, snapshotManager)
private val pruner = Pruner(crypto, backendManager, snapshotManager, blobCache)
private val folder = TopLevelFolder(repoId)

private val snapshotHandle1 =
Expand Down Expand Up @@ -84,6 +85,7 @@ internal class PrunerTest : TransportTest() {
blobIds.forEach {
coEvery { backend.remove(AppBackupFileType.Blob(repoId, it)) } just Runs
}
every { blobCache.onBlobsRemoved(blobIds.toSet()) } just Runs

pruner.removeOldSnapshotsAndPruneUnusedBlobs()
}
Expand Down Expand Up @@ -143,12 +145,14 @@ internal class PrunerTest : TransportTest() {
// now extra blobs will get removed
coEvery { backend.remove(AppBackupFileType.Blob(repoId, blob1)) } just Runs
coEvery { backend.remove(AppBackupFileType.Blob(repoId, blob2)) } just Runs
every { blobCache.onBlobsRemoved(setOf(blob1, blob2)) } just Runs

pruner.removeOldSnapshotsAndPruneUnusedBlobs()

coVerify {
backend.remove(AppBackupFileType.Blob(repoId, blob1))
backend.remove(AppBackupFileType.Blob(repoId, blob2))
blobCache.onBlobsRemoved(setOf(blob1, blob2))
}
}

Expand Down

0 comments on commit ae77ebe

Please sign in to comment.