From 14896594d845333858115672cf04e9b5ea004c12 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Wed, 2 Sep 2020 15:43:27 +0200 Subject: [PATCH] fix reading and writing of modification time. --- lib/src/kdbx_meta.dart | 9 +++++++-- lib/src/kdbx_times.dart | 7 ++++--- lib/src/kdbx_xml.dart | 10 +++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/src/kdbx_meta.dart b/lib/src/kdbx_meta.dart index 8439c80..3fcb7c3 100644 --- a/lib/src/kdbx_meta.dart +++ b/lib/src/kdbx_meta.dart @@ -14,6 +14,10 @@ import 'package:quiver/iterables.dart'; import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart'; +import 'package:logging/logging.dart'; + +final _logger = Logger('kdbx_meta'); + class KdbxMeta extends KdbxNode implements KdbxNodeContext { KdbxMeta.create({ @required String databaseName, @@ -182,8 +186,9 @@ class KdbxMeta extends KdbxNode implements KdbxNodeContext { defaultUserNameChanged.set(other.defaultUserNameChanged.get()); } if (other.masterKeyChanged.isAfter(masterKeyChanged)) { - throw UnimplementedError( - 'Other database changed master key. not supported.'); + // throw UnimplementedError( + // 'Other database changed master key. not supported.'); + _logger.shout('MasterKey was changed? We will not merge this (yet).'); } if (other.recycleBinChanged.isAfter(recycleBinChanged)) { recycleBinEnabled.set(other.recycleBinEnabled.get()); diff --git a/lib/src/kdbx_times.dart b/lib/src/kdbx_times.dart index 764ee5a..982fc2f 100644 --- a/lib/src/kdbx_times.dart +++ b/lib/src/kdbx_times.dart @@ -23,9 +23,10 @@ class KdbxTimes extends KdbxNode implements KdbxNodeContext { DateTimeUtcNode get creationTime => DateTimeUtcNode(this, 'CreationTime'); DateTimeUtcNode get lastModificationTime => - DateTimeUtcNode(this, 'CreationTime'); - DateTimeUtcNode get lastAccessTime => DateTimeUtcNode(this, 'CreationTime'); - DateTimeUtcNode get expiryTime => DateTimeUtcNode(this, 'CreationTime'); + DateTimeUtcNode(this, 'LastModificationTime', + defaultValue: () => creationTime.get() ?? DateTimeUtcNode.minDate); + DateTimeUtcNode get lastAccessTime => DateTimeUtcNode(this, 'LastAccessTime'); + DateTimeUtcNode get expiryTime => DateTimeUtcNode(this, 'ExpiryTime'); BooleanNode get expires => BooleanNode(this, 'Expires'); IntNode get usageCount => IntNode(this, 'UsageCount'); DateTimeUtcNode get locationChanged => diff --git a/lib/src/kdbx_xml.dart b/lib/src/kdbx_xml.dart index f432eac..d102f20 100644 --- a/lib/src/kdbx_xml.dart +++ b/lib/src/kdbx_xml.dart @@ -231,13 +231,17 @@ class BooleanNode extends KdbxSubTextNode { } class DateTimeUtcNode extends KdbxSubTextNode { - DateTimeUtcNode(KdbxNodeContext node, String name) : super(node, name); + DateTimeUtcNode(KdbxNodeContext node, String name, {this.defaultValue}) + : super(node, name); static const EpochSeconds = 62135596800; + final DateTime Function() defaultValue; KdbxReadWriteContext get _ctx => (node as KdbxNodeContext).ctx; + static final minDate = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true); - bool isAfter(DateTimeUtcNode other) => get().isAfter(other.get()); + bool isAfter(DateTimeUtcNode other) => + (get() ?? minDate).isAfter(other.get() ?? minDate); void setToNow() { set(clock.now().toUtc()); @@ -246,7 +250,7 @@ class DateTimeUtcNode extends KdbxSubTextNode { @override DateTime decode(String value) { if (value == null) { - return null; + return defaultValue?.call(); } if (value.contains(':')) { return DateTime.parse(value);