restoreOnto method
Replaces current storage with this snapshot's contents.
Failures after the clear phase rethrow a StateError naming which phase
failed (clear vs rewrite) so callers never see a half-restored device.
Implementation
Future<void> restoreOnto(StorageManager storage) async {
return await RunnerBenchmark.async('lifecycle', 'restoreOnto', () async {
await runRestorePhases(
clear: () => clearPersistentStorage(storage),
rewrite: () async {
for (final entry in publicStorage.entries) {
await storage.write(entry.key, _copy(entry.value));
}
for (final entry in secureStorage.entries) {
await storage.write(entry.key, _copy(entry.value));
}
for (final entry in keychain.entries) {
await storage.writeSecurely(
key: entry.key,
value: _copy(entry.value),
);
}
},
);
});
}