Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit bc14bd1

Browse files
Hideki Itakurapasin
authored andcommitted
Fixed Java Core Issue 1663 - 1.x: Channel removal potentially disrupt… (#99)
* Fixed Java Core Issue 1663 - 1.x: Channel removal potentially disrupts attachments - Ported fix from CBL .NET couchbase/couchbase-lite-net@07c1374 * Added the check the value of `_removed` key. * Added null check to json object.
1 parent ec06b94 commit bc14bd1

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/main/java/com/couchbase/lite/store/ForestDBStore.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ public RevisionList getAllRevisions(String docID, boolean onlyCurrent) {
465465
@Override
466466
public List<String> getPossibleAncestorRevisionIDs(RevisionInternal rev,
467467
int limit,
468-
AtomicBoolean outHaveBodies) {
468+
AtomicBoolean outHaveBodies,
469+
boolean withBodiesOnly) {
469470
int generation = RevisionInternal.generationFromRevID(rev.getRevID());
470471
if (generation <= 1)
471472
return null;
@@ -483,9 +484,27 @@ public List<String> getPossibleAncestorRevisionIDs(RevisionInternal rev,
483484
int revFlags = (int) doc.getSelectedRevFlags();
484485
if (((revFlags & C4RevisionFlags.kRevLeaf) != 0) == (leaf == 1 ? true : false) &&
485486
RevisionInternal.generationFromRevID(revID) < generation) {
486-
revIDs.add(revID);
487-
if (outHaveBodies != null && !doc.hasRevisionBody())
487+
488+
if (outHaveBodies != null && !doc.hasRevisionBody()) {
488489
outHaveBodies.set(false);
490+
if (withBodiesOnly)
491+
continue;
492+
}
493+
if (withBodiesOnly) {
494+
byte[] body = null;
495+
try {
496+
body = doc.getSelectedBody();
497+
} catch (ForestException e) {
498+
Log.e(TAG, e.toString(), e);
499+
}
500+
if (body != null && body.length > 0) {
501+
Map<String, Object> props = getDocProperties(body);
502+
if (props != null && props.containsKey("_removed") && (Boolean) props.get("_removed") == true)
503+
continue;
504+
}
505+
}
506+
507+
revIDs.add(revID);
489508
if (limit > 0 && revIDs.size() >= limit)
490509
break;
491510
}

0 commit comments

Comments
 (0)