fix backup on debug builds (#1728)
Some checks are pending
Cache Dependencies / test (push) Waiting to run

open transactionDecscriptionBox if it's not open
This commit is contained in:
cyan 2024-10-16 19:27:04 +02:00 committed by GitHub
parent 605d164998
commit 564f8e2c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:cake_wallet/core/secure_storage.dart'; import 'package:cake_wallet/core/secure_storage.dart';
import 'package:cake_wallet/entities/get_encryption_key.dart';
import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/transaction_description.dart';
import 'package:cake_wallet/themes/theme_list.dart'; import 'package:cake_wallet/themes/theme_list.dart';
import 'package:cw_core/root_dir.dart'; import 'package:cw_core/root_dir.dart';
@ -105,7 +106,15 @@ class BackupService {
if (entity.path == archivePath || entity.path == tmpDir.path) { if (entity.path == archivePath || entity.path == tmpDir.path) {
return; return;
} }
final filename = entity.absolute;
for (var ignore in ignoreFiles) {
final filename = entity.absolute.path;
if (filename.endsWith(ignore) && !filename.contains("wallets/")) {
print("ignoring backup file: $filename");
return;
}
}
print("restoring: $filename");
if (entity.statSync().type == FileSystemEntityType.directory) { if (entity.statSync().type == FileSystemEntityType.directory) {
zipEncoder.addDirectory(Directory(entity.path)); zipEncoder.addDirectory(Directory(entity.path));
} else { } else {
@ -148,14 +157,29 @@ class BackupService {
await _importPreferencesDump(); await _importPreferencesDump();
} }
// checked with .endsWith - so this should be the last part of the filename
static const ignoreFiles = [
"flutter_assets/kernel_blob.bin",
"flutter_assets/vm_snapshot_data",
"flutter_assets/isolate_snapshot_data",
".lock",
];
Future<void> _importBackupV2(Uint8List data, String password) async { Future<void> _importBackupV2(Uint8List data, String password) async {
final appDir = await getAppDir(); final appDir = await getAppDir();
final decryptedData = await _decryptV2(data, password); final decryptedData = await _decryptV2(data, password);
final zip = ZipDecoder().decodeBytes(decryptedData); final zip = ZipDecoder().decodeBytes(decryptedData);
outer:
for (var file in zip.files) { for (var file in zip.files) {
final filename = file.name; final filename = file.name;
for (var ignore in ignoreFiles) {
if (filename.endsWith(ignore) && !filename.contains("wallets/")) {
print("ignoring backup file: $filename");
continue outer;
}
}
print("restoring: $filename");
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)
@ -206,6 +230,16 @@ class BackupService {
json.decode(transactionDescriptionFile.readAsStringSync()) as Map<String, dynamic>; json.decode(transactionDescriptionFile.readAsStringSync()) as Map<String, dynamic>;
final descriptionsMap = jsonData.map((key, value) => final descriptionsMap = jsonData.map((key, value) =>
MapEntry(key, TransactionDescription.fromJson(value as Map<String, dynamic>))); MapEntry(key, TransactionDescription.fromJson(value as Map<String, dynamic>)));
if (!_transactionDescriptionBox.isOpen) {
final transactionDescriptionsBoxKey = await getEncryptionKey(secureStorage: secureStorageShared, forKey: TransactionDescription.boxKey);
final transactionDescriptionBox = await CakeHive.openBox<TransactionDescription>(
TransactionDescription.boxName,
encryptionKey: transactionDescriptionsBoxKey,
);
await transactionDescriptionBox.putAll(descriptionsMap);
return;
}
await _transactionDescriptionBox.putAll(descriptionsMap); await _transactionDescriptionBox.putAll(descriptionsMap);
} }