Skip to content

Commit

Permalink
Fix attachment revpos not being set when follows=true
Browse files Browse the repository at this point in the history
During the pull replication, the revpos of an attachment could be set to a parent revision while the follows=true. If the revpos value doesn't get preserved, the revpos will be set to the current generation.

Later, when pushing an updated document again, the attachment info will contain a wrong revpos and result to the missing_stub error on CouchDB. SyncGateway currently ignores the issue and doesn't overwrite the revpos value on the server side.

#817
  • Loading branch information
pasin committed Jul 30, 2015
1 parent 93b811c commit 16b459d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Source/CBL_Attachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ - (instancetype) initWithName: (NSString*)name
*outStatus = kCBLStatusBadAttachment;
return nil;
}
// #817: There could be a revpos set to a parent revision:
id revPosObj = attachInfo[@"revpos"];
if (revPosObj) {
int revPos = [$castIf(NSNumber, revPosObj) intValue];
if (revPos <= 0) {
*outStatus = kCBLStatusBadAttachment;
return nil;
}
self->revpos = (unsigned)revPos;
}
} else {
*outStatus = kCBLStatusBadAttachment;
return nil;
Expand Down
21 changes: 21 additions & 0 deletions Unit-Tests/DatabaseAttachment_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,27 @@ - (void) test14_FollowingAttachments {
}


- (void) test16_FollowWithRevpos {
NSDictionary* attachInfo = $dict({@"content_type", @"text/plain"},
{@"digest", @"md5-DaUdFsLh8FKLbcBIDlU57g=="},
{@"follows", @YES},
{@"length", @51200},
{@"revpos", @2});
CBLStatus status;
CBL_Attachment *attachment = [[CBL_Attachment alloc] initWithName: @"attachment"
info: attachInfo
status: &status];
Assert(attachment);
Assert(status != kCBLStatusBadAttachment);
NSDictionary* stub = [attachment asStubDictionary];
AssertEqualish(stub, $dict({@"content_type", @"text/plain"},
{@"digest", @"sha1-AAAAAAAAAAAAAAAAAAAAAAAAAAA="},
{@"length", @51200},
{@"revpos", @2},
{@"stub", @YES}));
}


static NSDictionary* attachmentsDict(NSData* data, NSString* name, NSString* type, BOOL gzipped) {
if (gzipped)
data = [NSData gtm_dataByGzippingData: data];
Expand Down

0 comments on commit 16b459d

Please sign in to comment.