Browse Source

kdbx4.1: keep track of PreviousParentGroup

pull/5/head
Herbert Poul 3 years ago
parent
commit
09fd6878b1
  1. 1
      lib/src/kdbx_header.dart
  2. 8
      lib/src/kdbx_object.dart
  3. 1
      lib/src/kdbx_xml.dart
  4. 12
      test/deleted_objects_test.dart

1
lib/src/kdbx_header.dart

@ -71,6 +71,7 @@ class KdbxVersion {
static const V3 = KdbxVersion._(3, 0);
static const V3_1 = KdbxVersion._(3, 1);
static const V4 = KdbxVersion._(4, 0);
static const V4_1 = KdbxVersion._(4, 1);
final int major;
final int minor;

8
lib/src/kdbx_object.dart

@ -192,6 +192,9 @@ abstract class KdbxObject extends KdbxNode {
KdbxGroup? _parent;
late final UuidNode previousParentGroup =
UuidNode(this, 'PreviousParentGroup');
KdbxCustomIcon? get customIcon =>
customIconUuid.get()?.let((uuid) => file!.body.meta.customIcons[uuid]);
@ -237,7 +240,10 @@ abstract class KdbxObject extends KdbxNode {
@internal
void internalChangeParent(KdbxGroup? parent) {
modify(() => _parent = parent);
modify(() {
previousParentGroup.set(_parent?.uuid);
_parent = parent;
});
}
void merge(MergeContext mergeContext, covariant KdbxObject other);

1
lib/src/kdbx_xml.dart

@ -28,6 +28,7 @@ class KdbxXml {
static const ATTR_ID = 'ID';
static const NODE_BINARY = 'Binary';
static const ATTR_REF = 'Ref';
static const NODE_PREVIOUS_PARENT_GROUP = 'PreviousParentGroup';
static const NODE_CUSTOM_ICONS = 'CustomIcons';
/// CustomIcons >> Icon

12
test/deleted_objects_test.dart

@ -25,6 +25,18 @@ void main() {
expect(reload.body.deletedObjects, hasLength(1));
});
});
group('delete to trash', () {
test('move to trash, read previous parent', () {
final file = testUtil.createEmptyFile();
final g = file.body.rootGroup;
final entry = testUtil.createEntry(file, g, 'foo', 'bar');
expect(g.getAllGroupsAndEntries(), hasLength(2));
file.deleteEntry(entry);
// root group, entry and trash group.
expect(g.getAllGroupsAndEntries(), hasLength(3));
expect(entry.previousParentGroup.get(), g.uuid);
});
});
group('delete permanently', () {
test('delete entry', () async {
final file = testUtil.createEmptyFile();

Loading…
Cancel
Save