Skip to content

Commit

Permalink
Reset latest snapshot to avoid it getting stale
Browse files Browse the repository at this point in the history
When switching to new storage that doesn't yet have any snapshots, we would otherwise keep the old latest snapshot around.
  • Loading branch information
grote committed Oct 1, 2024
1 parent 44d4e58 commit 7ff6c52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ internal class SnapshotManager(
* currently available on the backend.
*/
suspend fun onSnapshotsLoaded(handles: List<AppBackupFileType.Snapshot>): List<Snapshot> {
// first reset latest snapshot, otherwise we'd hang on to a stale one
// e.g. when switching to new storage without any snapshots
latestSnapshot = null
return handles.mapNotNull { snapshotHandle ->
val snapshot = try {
loadSnapshot(snapshotHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.calyxos.seedvault.core.toHexString
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
Expand Down Expand Up @@ -75,6 +76,10 @@ internal class SnapshotManagerTest : TransportTest() {

// snapshot with largest token is latest
assertEquals(20, snapshotManager.latestSnapshot?.token)

// when switching storage and now not having any snapshots, we must clear latestSnapshot
snapshotManager.onSnapshotsLoaded(emptyList())
assertNull(snapshotManager.latestSnapshot)
}

@Test
Expand Down

0 comments on commit 7ff6c52

Please sign in to comment.