Browse Source

ignore missing recycle bin.

remove-cryptography-dependency
Herbert Poul 5 years ago
parent
commit
a580803a8d
  1. 14
      lib/src/kdbx_dao.dart
  2. 51
      lib/src/kdbx_file.dart

14
lib/src/kdbx_dao.dart

@ -20,20 +20,6 @@ extension KdbxDao on KdbxFile {
orElse: () => orElse: () =>
throw StateError('Unable to find group with uuid $uuid')); throw StateError('Unable to find group with uuid $uuid'));
KdbxGroup _createRecycleBin() {
body.meta.recycleBinEnabled.set(true);
final group = createGroup(parent: body.rootGroup, name: 'Trash');
group.icon.set(KdbxIcon.TrashBin);
group.enableAutoType.set(false);
group.enableSearching.set(false);
body.meta.recycleBinUUID.set(group.uuid);
return group;
}
KdbxGroup getRecycleBinOrCreate() {
return recycleBin ?? _createRecycleBin();
}
void deleteGroup(KdbxGroup group) { void deleteGroup(KdbxGroup group) {
move(group, getRecycleBinOrCreate()); move(group, getRecycleBinOrCreate());
} }

51
lib/src/kdbx_file.dart

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:kdbx/src/crypto/protected_value.dart'; import 'package:kdbx/src/crypto/protected_value.dart';
import 'package:kdbx/src/kdbx_consts.dart';
import 'package:kdbx/src/kdbx_dao.dart'; import 'package:kdbx/src/kdbx_dao.dart';
import 'package:kdbx/src/kdbx_format.dart'; import 'package:kdbx/src/kdbx_format.dart';
import 'package:kdbx/src/kdbx_group.dart'; import 'package:kdbx/src/kdbx_group.dart';
@ -67,18 +68,18 @@ class KdbxFile {
_dirtyObjectsChanged.close(); _dirtyObjectsChanged.close();
} }
KdbxGroup _recycleBin; CachedValue<KdbxGroup> _recycleBin;
/// Returns the recycle bin, if it exists, null otherwise. /// Returns the recycle bin, if it exists, null otherwise.
KdbxGroup get recycleBin => _recycleBin ??= _findRecycleBin(); KdbxGroup get recycleBin => (_recycleBin ??= _findRecycleBin()).value;
KdbxGroup _findRecycleBin() { CachedValue<KdbxGroup> _findRecycleBin() {
final uuid = body.meta.recycleBinUUID.get(); final uuid = body.meta.recycleBinUUID.get();
if (uuid?.isNil != false) { if (uuid?.isNil != false) {
return null; return CachedValue.withNull();
} }
try { try {
return findGroupByUuid(uuid); return CachedValue.withValue(findGroupByUuid(uuid));
} catch (e, stackTrace) { } catch (e, stackTrace) {
_logger.warning(() { _logger.warning(() {
final groupDebug = body.rootGroup final groupDebug = body.rootGroup
@ -89,25 +90,29 @@ class KdbxFile {
}); });
_logger.severe('Inconsistency error, uuid $uuid not found in groups.', e, _logger.severe('Inconsistency error, uuid $uuid not found in groups.', e,
stackTrace); stackTrace);
rethrow; return CachedValue.withNull();
} }
} }
// void _subscribeToChildren() { KdbxGroup _createRecycleBin() {
// final allObjects = _allObjects; body.meta.recycleBinEnabled.set(true);
// for (final obj in allObjects) { final group = createGroup(parent: body.rootGroup, name: 'Trash');
// _subscriptions.handle(obj.changes.listen((event) { group.icon.set(KdbxIcon.TrashBin);
// if (event.isDirty) { group.enableAutoType.set(false);
// isDirty = true; group.enableSearching.set(false);
// if (event.object is KdbxGroup) { body.meta.recycleBinUUID.set(group.uuid);
// Future(() { _recycleBin = CachedValue.withValue(group);
// // resubscribe, just in case some child groups/entries have changed. return group;
// _subscriptions.cancelSubscriptions(); }
// _subscribeToChildren();
// }); KdbxGroup getRecycleBinOrCreate() {
// } return recycleBin ?? _createRecycleBin();
// } }
// })); }
// }
// } class CachedValue<T> {
CachedValue.withNull() : value = null;
CachedValue.withValue(this.value) : assert(value != null);
final T value;
} }

Loading…
Cancel
Save