Fix potential error reconciling changes after 3fbb17a2e6

This commit is contained in:
Dan Stillman 2019-05-08 06:20:00 -04:00
parent 3fbb17a2e6
commit 32de0d4037

View file

@ -1481,6 +1481,7 @@ Zotero.Sync.Data.Local = {
Zotero.debug(changeset2);
var conflicts = [];
var matchedLocalChanges = new Set();
for (let i = 0; i < changeset1.length; i++) {
for (let j = 0; j < changeset2.length; j++) {
@ -1541,7 +1542,7 @@ Zotero.Sync.Data.Local = {
let creators2 = c2.value;
if (creators1.length == creators2.length
&& creators1.every((c, index) => Zotero.Creators.equals(c, creators2[index]))) {
changeset1.splice(i--, 1);
matchedLocalChanges.add(i);
changeset2.splice(j--, 1);
continue;
}
@ -1549,6 +1550,7 @@ Zotero.Sync.Data.Local = {
// Removed on both sides
if (c1.op == 'delete' && c2.op == 'delete') {
matchedLocalChanges.add(i);
changeset2.splice(j--, 1);
continue;
}
@ -1558,7 +1560,7 @@ Zotero.Sync.Data.Local = {
|| (c1.op == 'member-remove' && c2.op == 'member-remove')
|| (c1.op == 'property-member-add' && c2.op == 'property-member-add')
|| (c1.op == 'property-member-remove' && c2.op == 'property-member-remove')) {
changeset1.splice(i--, 1);
matchedLocalChanges.add(i);
changeset2.splice(j--, 1);
continue;
}
@ -1566,7 +1568,7 @@ Zotero.Sync.Data.Local = {
// If both sides have values, see if they're the same, and if so remove the
// second one
if (c1.op != 'delete' && c2.op != 'delete' && c1.value === c2.value) {
changeset1.splice(i--, 1);
matchedLocalChanges.add(i);
changeset2.splice(j--, 1);
continue;
}
@ -1579,7 +1581,7 @@ Zotero.Sync.Data.Local = {
}
// Conflict
changeset1.splice(i--, 1);
matchedLocalChanges.add(i);
changeset2.splice(j--, 1);
conflicts.push([c1, c2]);
}
@ -1588,9 +1590,9 @@ Zotero.Sync.Data.Local = {
return {
changes: changeset2,
conflicts,
// If there were unique local changes, we need to know that so the item can be kept as
// unsynced
localChanged: !!changeset1.length
// If there were local changes that weren't made remotely as well, the item needs to be
// kept as unsynced
localChanged: changeset1.length > matchedLocalChanges.size
};
},