Reset latest snapshot to avoid it getting stale
When switching to new storage that doesn't yet have any snapshots, we would otherwise keep the old latest snapshot around.
This commit is contained in:
parent
7696b88a5a
commit
11270ff694
2 changed files with 8 additions and 0 deletions
|
@ -47,6 +47,9 @@ internal class SnapshotManager(
|
||||||
* currently available on the backend.
|
* currently available on the backend.
|
||||||
*/
|
*/
|
||||||
suspend fun onSnapshotsLoaded(handles: List<AppBackupFileType.Snapshot>): List<Snapshot> {
|
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 ->
|
return handles.mapNotNull { snapshotHandle ->
|
||||||
val snapshot = try {
|
val snapshot = try {
|
||||||
loadSnapshot(snapshotHandle)
|
loadSnapshot(snapshotHandle)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.calyxos.seedvault.core.toHexString
|
||||||
import org.junit.jupiter.api.Assertions.assertArrayEquals
|
import org.junit.jupiter.api.Assertions.assertArrayEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
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.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.io.TempDir
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
@ -75,6 +76,10 @@ internal class SnapshotManagerTest : TransportTest() {
|
||||||
|
|
||||||
// snapshot with largest token is latest
|
// snapshot with largest token is latest
|
||||||
assertEquals(20, snapshotManager.latestSnapshot?.token)
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue