Set flush: true in backup service (#1717)

This should ensure that files are flushed to disk before this function
returns.
Also, replaced foreach loop with for loop.
This commit is contained in:
cyan 2024-10-04 23:53:55 +02:00 committed by GitHub
parent dfccedddb2
commit cc61a25cd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -130,18 +130,18 @@ class BackupService {
final decryptedData = await _decryptV1(data, password, nonce); final decryptedData = await _decryptV1(data, password, nonce);
final zip = ZipDecoder().decodeBytes(decryptedData); final zip = ZipDecoder().decodeBytes(decryptedData);
zip.files.forEach((file) { for (var file in zip.files) {
final filename = file.name; final filename = file.name;
if (file.isFile) { if (file.isFile) {
final content = file.content as List<int>; final content = file.content as List<int>;
File('${appDir.path}/' + filename) File('${appDir.path}/' + filename)
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsBytesSync(content); ..writeAsBytesSync(content, flush: true);
} else { } else {
Directory('${appDir.path}/' + filename)..create(recursive: true); Directory('${appDir.path}/' + filename)..create(recursive: true);
} }
}); };
await _verifyWallets(); await _verifyWallets();
await _importKeychainDumpV1(password, nonce: nonce); await _importKeychainDumpV1(password, nonce: nonce);
@ -153,18 +153,18 @@ class BackupService {
final decryptedData = await _decryptV2(data, password); final decryptedData = await _decryptV2(data, password);
final zip = ZipDecoder().decodeBytes(decryptedData); final zip = ZipDecoder().decodeBytes(decryptedData);
zip.files.forEach((file) { for (var file in zip.files) {
final filename = file.name; final filename = file.name;
if (file.isFile) { if (file.isFile) {
final content = file.content as List<int>; final content = file.content as List<int>;
File('${appDir.path}/' + filename) File('${appDir.path}/' + filename)
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsBytesSync(content); ..writeAsBytesSync(content, flush: true);
} else { } else {
Directory('${appDir.path}/' + filename)..create(recursive: true); Directory('${appDir.path}/' + filename)..create(recursive: true);
} }
}); };
await _verifyWallets(); await _verifyWallets();
await _importKeychainDumpV2(password); await _importKeychainDumpV2(password);