Skip to content

Commit

Permalink
CBL-624: fix: flags not carrying over(master branch) (#2599)
Browse files Browse the repository at this point in the history
* fixed the issue with attachment flag not carrying over
* include unit test to verify the hasAttachmentFlag is carried over
* corrected the revisionFlag property.
  • Loading branch information
jayahariv authored and pasin committed Jan 14, 2020
1 parent c727517 commit a2477fe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions Objective-C/CBLDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ - (BOOL) saveResolvedDocument: (CBLDocument*)resolvedDoc
if (resolvedDoc != remoteDoc) {
BOOL isDeleted = YES;
if (resolvedDoc) {
mergedFlags = resolvedDoc.c4Doc != nil ? resolvedDoc.c4Doc.revFlags : 0;
@try {
// Unless the remote revision is being used as-is, we need a new revision:
mergedBody = [resolvedDoc encode: outError];
Expand Down
4 changes: 2 additions & 2 deletions Objective-C/CBLDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ - (BOOL) selectConflictingRevision {

BOOL foundConflict = NO;
while(!foundConflict && c4doc_selectNextLeafRevision(_c4Doc.rawDoc, true, true, nullptr)) {
foundConflict = (_c4Doc.flags & kRevIsConflict) != 0;
foundConflict = (_c4Doc.revFlags & kRevIsConflict) != 0;
}
if (foundConflict)
self.c4Doc = _c4Doc; // This will update to the selected revision
Expand Down Expand Up @@ -244,7 +244,7 @@ - (NSUInteger) generation {

- (BOOL) isDeleted {
CBL_LOCK(self) {
return _c4Doc != nil ? (_c4Doc.flags & kDocDeleted) != 0 : NO;
return _c4Doc != nil ? (_c4Doc.revFlags & kRevDeleted) != 0 : NO;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Objective-C/Internal/CBLC4Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (readonly, nonatomic) C4Document* rawDoc;

@property (readonly, nonatomic) C4DocumentFlags flags;
@property (readonly, nonatomic) C4RevisionFlags revFlags;

@property (readonly, nonatomic) C4SequenceNumber sequence;

Expand Down
2 changes: 1 addition & 1 deletion Objective-C/Internal/CBLC4Document.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (C4Document*) rawDoc {
return _rawDoc;
}

- (C4DocumentFlags) flags {
- (C4RevisionFlags) revFlags {
return _rawDoc->selectedRev.flags;
}

Expand Down
28 changes: 28 additions & 0 deletions Objective-C/Tests/ReplicatorTest+CustomConflict.m
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,34 @@ - (void) testConflictResolverWhenDocumentIsPurged {
[replicator removeChangeListenerWithToken: token];
}

- (void) testConflictResolverPreservesFlags {
NSString* docId = @"doc";
NSData* content = [@"I'm a blob." dataUsingEncoding: NSUTF8StringEncoding];
CBLBlob* blob = [[CBLBlob alloc] initWithContentType:@"text/plain" data: content];
NSDictionary* localData = @{@"key1": @"value1", @"blob": blob};
NSDictionary* remoteData = @{@"key2": @"value2"};
[self makeConflictFor: docId withLocal: localData withRemote: remoteData];

CBLDocument* localDoc = [self.db documentWithID: docId];
Assert(0 != localDoc.c4Doc.revFlags);
Assert(localDoc.c4Doc.revFlags & kRevHasAttachments);

TestConflictResolver* resolver;
CBLReplicatorConfiguration* pullConfig = [self config: kCBLReplicatorTypePull];

__block C4RevisionFlags localRevFlags = 0;
resolver = [[TestConflictResolver alloc] initWithResolver: ^CBLDocument* (CBLConflict* con) {
localRevFlags = con.localDocument.c4Doc.revFlags;
return con.localDocument;
}];

pullConfig.conflictResolver = resolver;
[self run: pullConfig errorCode: 0 errorDomain: nil];

localDoc = [self.db documentWithID: docId];
Assert(localDoc.c4Doc.revFlags & kRevHasAttachments & localRevFlags);
}

#endif

@end
Expand Down

0 comments on commit a2477fe

Please sign in to comment.