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.

cyan committed Oct 4, 2024 at 23:53 UTC cc61a25cd17f8662f56672e4d19f0a43579057f3
1 file changed +6 -6
lib/core/backup_service.dart
+6 -6
@@ -130,18 +130,18 @@ class BackupService {
130 final decryptedData = await _decryptV1(data, password, nonce);
131 final zip = ZipDecoder().decodeBytes(decryptedData);
132
133 - zip.files.forEach((file) {
133 + for (var file in zip.files) {
134 final filename = file.name;
135
136 if (file.isFile) {
137 final content = file.content as List<int>;
138 File('${appDir.path}/' + filename)
139 ..createSync(recursive: true)
140 - ..writeAsBytesSync(content);
140 + ..writeAsBytesSync(content, flush: true);
141 } else {
142 Directory('${appDir.path}/' + filename)..create(recursive: true);
143 }
144 - });
144 + };
145
146 await _verifyWallets();
147 await _importKeychainDumpV1(password, nonce: nonce);
@@ -153,18 +153,18 @@ class BackupService {
153 final decryptedData = await _decryptV2(data, password);
154 final zip = ZipDecoder().decodeBytes(decryptedData);
155
156 - zip.files.forEach((file) {
156 + for (var file in zip.files) {
157 final filename = file.name;
158
159 if (file.isFile) {
160 final content = file.content as List<int>;
161 File('${appDir.path}/' + filename)
162 ..createSync(recursive: true)
163 - ..writeAsBytesSync(content);
163 + ..writeAsBytesSync(content, flush: true);
164 } else {
165 Directory('${appDir.path}/' + filename)..create(recursive: true);
166 }
167 - });
167 + };
168
169 await _verifyWallets();
170 await _importKeychainDumpV2(password);