Browse Source

fixed bug saving files with history entries which contain attachments.

pull/3/head
Herbert Poul 4 years ago
parent
commit
7788c0fba1
  1. 1
      bin/kdbx.dart
  2. 12
      lib/src/kdbx_entry.dart
  3. 14
      lib/src/kdbx_object.dart
  4. 1
      test/kdbx4_test.dart

1
bin/kdbx.dart

@ -27,7 +27,6 @@ void main(List<String> arguments) {
} }
print(error); print(error);
exit(64); exit(64);
return null;
}); });
// final inputFile = args['input'] as String; // final inputFile = args['input'] as String;

12
lib/src/kdbx_entry.dart

@ -85,6 +85,16 @@ class KdbxEntry extends KdbxObject {
final List<KdbxEntry> history; final List<KdbxEntry> history;
@override
set file(KdbxFile file) {
super.file = file;
// TODO this looks like some weird workaround, get rid of the
// `file` reference.
for (final historyEntry in history) {
historyEntry.file = file;
}
}
XmlElement get _historyElement => node XmlElement get _historyElement => node
.findElements(KdbxXml.NODE_HISTORY) .findElements(KdbxXml.NODE_HISTORY)
.singleWhere((_) => true, orElse: () { .singleWhere((_) => true, orElse: () {
@ -132,7 +142,7 @@ class KdbxEntry extends KdbxObject {
if (binary.isInline) { if (binary.isInline) {
binary.saveToXml(value); binary.saveToXml(value);
} else { } else {
final binaryIndex = file.ctx.findBinaryId(binary); final binaryIndex = ctx.findBinaryId(binary);
value.addAttribute(KdbxXml.ATTR_REF, binaryIndex.toString()); value.addAttribute(KdbxXml.ATTR_REF, binaryIndex.toString());
} }
return XmlElement(XmlName(KdbxXml.NODE_BINARY)) return XmlElement(XmlName(KdbxXml.NODE_BINARY))

14
lib/src/kdbx_object.dart

@ -75,22 +75,26 @@ abstract class KdbxNode with Changeable<KdbxNode> {
} }
abstract class KdbxObject extends KdbxNode { abstract class KdbxObject extends KdbxNode {
KdbxObject.create( KdbxObject.create(this.ctx, this.file, String nodeName, KdbxGroup parent)
KdbxReadWriteContext ctx, this.file, String nodeName, KdbxGroup parent) : assert(ctx != null),
: times = KdbxTimes.create(ctx), times = KdbxTimes.create(ctx),
_parent = parent, _parent = parent,
super.create(nodeName) { super.create(nodeName) {
_uuid.set(KdbxUuid.random()); _uuid.set(KdbxUuid.random());
} }
KdbxObject.read(KdbxReadWriteContext ctx, KdbxGroup parent, XmlElement node) KdbxObject.read(this.ctx, KdbxGroup parent, XmlElement node)
: times = KdbxTimes.read(node.findElements('Times').single, ctx), : assert(ctx != null),
times = KdbxTimes.read(node.findElements('Times').single, ctx),
_parent = parent, _parent = parent,
super.read(node); super.read(node);
/// the file this object is part of. will be set AFTER loading, etc. /// the file this object is part of. will be set AFTER loading, etc.
/// TODO: We should probably get rid of this `file` reference.
KdbxFile file; KdbxFile file;
final KdbxReadWriteContext ctx;
final KdbxTimes times; final KdbxTimes times;
KdbxUuid get uuid => _uuid.get(); KdbxUuid get uuid => _uuid.get();

1
test/kdbx4_test.dart

@ -1,6 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'package:argon2_ffi_base/argon2_ffi_base.dart';
import 'package:kdbx/kdbx.dart'; import 'package:kdbx/kdbx.dart';
import 'package:kdbx/src/kdbx_header.dart'; import 'package:kdbx/src/kdbx_header.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';

Loading…
Cancel
Save