From 09fd6878b1094e3a00c16d06c6ff1bc6cb9e7902 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Fri, 30 Jul 2021 12:53:13 +0200 Subject: [PATCH] kdbx4.1: keep track of PreviousParentGroup --- lib/src/kdbx_header.dart | 1 + lib/src/kdbx_object.dart | 8 +++++++- lib/src/kdbx_xml.dart | 1 + test/deleted_objects_test.dart | 12 ++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/src/kdbx_header.dart b/lib/src/kdbx_header.dart index ba71a5a..1b3d58f 100644 --- a/lib/src/kdbx_header.dart +++ b/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; diff --git a/lib/src/kdbx_object.dart b/lib/src/kdbx_object.dart index d40cf25..23361fa 100644 --- a/lib/src/kdbx_object.dart +++ b/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); diff --git a/lib/src/kdbx_xml.dart b/lib/src/kdbx_xml.dart index 0a285a2..3e334fc 100644 --- a/lib/src/kdbx_xml.dart +++ b/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 diff --git a/test/deleted_objects_test.dart b/test/deleted_objects_test.dart index f8e35ba..80edf6c 100644 --- a/test/deleted_objects_test.dart +++ b/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();