Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Feb 10, 2024
1 parent 4c280b3 commit 70c0fa1
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lib/src/kdbx_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,17 @@ class KdbxMeta extends KdbxNode implements KdbxNodeContext {
final otherIsNewer = other.settingsChanged.isAfter(settingsChanged);

// merge custom data
for (final otherCustomDataEntry in other.customData.entries) {
if ((otherIsNewer || !customData.containsKey(otherCustomDataEntry.key)) &&
!ctx.deletedObjects.containsKey(otherCustomDataEntry.key)) {
customData[otherCustomDataEntry.key] = otherCustomDataEntry.value;
}
}
// for (final otherCustomDataEntry in other.customData.entries) {
// if ((otherIsNewer || !customData.containsKey(otherCustomDataEntry.key)) &&
// !ctx.deletedObjects.containsKey(otherCustomDataEntry.key)) {
// customData[otherCustomDataEntry.key] = otherCustomDataEntry.value;
// }
// }
mergeKdbxMetaCustomDataWithDates(customData, other.customData, ctx, true);

// merge custom icons
// Unused icons will be cleaned up later
//TODO: Use modified dates for better merging?
for (final otherCustomIcon in other._customIcons.values) {
_customIcons[otherCustomIcon.uuid] ??= otherCustomIcon;
}
Expand All @@ -294,6 +296,34 @@ class KdbxMeta extends KdbxNode implements KdbxNodeContext {
}
}

void mergeKdbxMetaCustomDataWithDates(
KdbxMetaCustomData local,
KdbxMetaCustomData other,
MergeContext ctx,
bool assumeRemoteIsNewerWhenDatesMissing) {
for (final entry in other.entries) {
final otherKey = entry.key;
final otherItem = entry.value;
final existingItem = local[otherKey];
if (existingItem != null) {
if ((existingItem.lastModified == null ||
otherItem.lastModified == null) &&
assumeRemoteIsNewerWhenDatesMissing) {
local[otherKey] = (
value: otherItem.value,
lastModified: otherItem.lastModified ?? clock.now().toUtc(),
);
} else if (existingItem.lastModified != null &&
otherItem.lastModified != null &&
otherItem.lastModified!.isAfter(existingItem.lastModified!)) {
local[otherKey] = otherItem;
}
} else if (!ctx.deletedObjects.containsKey(otherKey)) {
local[otherKey] = otherItem;
}
}
}

// Import changes in [other] into this meta data.
void import(KdbxMeta other) {
// import custom icons
Expand Down

0 comments on commit 70c0fa1

Please sign in to comment.