Browse Source

fix reading and writing of modification time.

pull/3/head
Herbert Poul 4 years ago
parent
commit
14896594d8
  1. 9
      lib/src/kdbx_meta.dart
  2. 7
      lib/src/kdbx_times.dart
  3. 10
      lib/src/kdbx_xml.dart

9
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' as xml;
import 'package:xml/xml.dart'; import 'package:xml/xml.dart';
import 'package:logging/logging.dart';
final _logger = Logger('kdbx_meta');
class KdbxMeta extends KdbxNode implements KdbxNodeContext { class KdbxMeta extends KdbxNode implements KdbxNodeContext {
KdbxMeta.create({ KdbxMeta.create({
@required String databaseName, @required String databaseName,
@ -182,8 +186,9 @@ class KdbxMeta extends KdbxNode implements KdbxNodeContext {
defaultUserNameChanged.set(other.defaultUserNameChanged.get()); defaultUserNameChanged.set(other.defaultUserNameChanged.get());
} }
if (other.masterKeyChanged.isAfter(masterKeyChanged)) { if (other.masterKeyChanged.isAfter(masterKeyChanged)) {
throw UnimplementedError( // throw UnimplementedError(
'Other database changed master key. not supported.'); // 'Other database changed master key. not supported.');
_logger.shout('MasterKey was changed? We will not merge this (yet).');
} }
if (other.recycleBinChanged.isAfter(recycleBinChanged)) { if (other.recycleBinChanged.isAfter(recycleBinChanged)) {
recycleBinEnabled.set(other.recycleBinEnabled.get()); recycleBinEnabled.set(other.recycleBinEnabled.get());

7
lib/src/kdbx_times.dart

@ -23,9 +23,10 @@ class KdbxTimes extends KdbxNode implements KdbxNodeContext {
DateTimeUtcNode get creationTime => DateTimeUtcNode(this, 'CreationTime'); DateTimeUtcNode get creationTime => DateTimeUtcNode(this, 'CreationTime');
DateTimeUtcNode get lastModificationTime => DateTimeUtcNode get lastModificationTime =>
DateTimeUtcNode(this, 'CreationTime'); DateTimeUtcNode(this, 'LastModificationTime',
DateTimeUtcNode get lastAccessTime => DateTimeUtcNode(this, 'CreationTime'); defaultValue: () => creationTime.get() ?? DateTimeUtcNode.minDate);
DateTimeUtcNode get expiryTime => DateTimeUtcNode(this, 'CreationTime'); DateTimeUtcNode get lastAccessTime => DateTimeUtcNode(this, 'LastAccessTime');
DateTimeUtcNode get expiryTime => DateTimeUtcNode(this, 'ExpiryTime');
BooleanNode get expires => BooleanNode(this, 'Expires'); BooleanNode get expires => BooleanNode(this, 'Expires');
IntNode get usageCount => IntNode(this, 'UsageCount'); IntNode get usageCount => IntNode(this, 'UsageCount');
DateTimeUtcNode get locationChanged => DateTimeUtcNode get locationChanged =>

10
lib/src/kdbx_xml.dart

@ -231,13 +231,17 @@ class BooleanNode extends KdbxSubTextNode<bool> {
} }
class DateTimeUtcNode extends KdbxSubTextNode<DateTime> { class DateTimeUtcNode extends KdbxSubTextNode<DateTime> {
DateTimeUtcNode(KdbxNodeContext node, String name) : super(node, name); DateTimeUtcNode(KdbxNodeContext node, String name, {this.defaultValue})
: super(node, name);
static const EpochSeconds = 62135596800; static const EpochSeconds = 62135596800;
final DateTime Function() defaultValue;
KdbxReadWriteContext get _ctx => (node as KdbxNodeContext).ctx; 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() { void setToNow() {
set(clock.now().toUtc()); set(clock.now().toUtc());
@ -246,7 +250,7 @@ class DateTimeUtcNode extends KdbxSubTextNode<DateTime> {
@override @override
DateTime decode(String value) { DateTime decode(String value) {
if (value == null) { if (value == null) {
return null; return defaultValue?.call();
} }
if (value.contains(':')) { if (value.contains(':')) {
return DateTime.parse(value); return DateTime.parse(value);

Loading…
Cancel
Save