Skip to content

Commit

Permalink
Add some comments to storage Restore
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Nov 27, 2023
1 parent 9aa57ca commit 8eba808
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import kotlin.time.ExperimentalTime

private const val TAG = "Restore"

@Suppress("BlockingMethodInNonBlockingContext")
internal class Restore(
context: Context,
private val storagePlugin: StoragePlugin,
Expand Down Expand Up @@ -57,14 +56,15 @@ internal class Restore(
MultiChunkRestore(context, storagePlugin, fileRestore, streamCrypto, streamKey)
}

@OptIn(ExperimentalTime::class)
fun getBackupSnapshots(): Flow<SnapshotResult> = flow {
val numSnapshots: Int
val time = measure {
val list = try {
// get all available backups, they may not be usable
storagePlugin.getBackupSnapshotsForRestore().sortedByDescending { storedSnapshot ->
storedSnapshot.timestamp
}.map { storedSnapshot ->
// as long as snapshot is null, it can't be used for restore
SnapshotItem(storedSnapshot, null)
}.toMutableList()
} catch (e: Exception) {
Expand All @@ -74,6 +74,7 @@ internal class Restore(
}
// return list copies, so this works with ListAdapter and DiffUtils
emit(SnapshotResult.Success(ArrayList(list)))
// try to decrypt snapshots and replace list items, if we can decrypt, otherwise remove
numSnapshots = list.size
val iterator = list.listIterator()
while (iterator.hasNext()) {
Expand Down

0 comments on commit 8eba808

Please sign in to comment.