Skip to content

Commit

Permalink
Merge pull request #650 from couchbase/feature/issue_649_attachment_c…
Browse files Browse the repository at this point in the history
…rash

Handle unable to create a blob store writer for the attachment

For #649 (should prevent the crash, at least)
  • Loading branch information
snej committed Apr 9, 2015
2 parents 0586286 + 94f5107 commit bbd3b72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Source/CBLMultipartDocumentReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,15 @@ - (BOOL) startedPart: (NSDictionary*)headers {
// format generated by -[CBL_Pusher uploadMultipartRevision:]. CouchDB (as of 1.2) doesn't
// output any headers at all on attachments so there's no compatibility issue yet.
NSString* name = CBLUnquoteString([disposition substringFromIndex: 21]);
if (name)
_attachmentsByName[name] = _curAttachment;
if (name) {
if (_curAttachment)
_attachmentsByName[name] = _curAttachment;
else {
Warn(@"Cannot create a blob store writer for the attachement.");
_status = kCBLStatusAttachmentError;
return NO;
}
}
}
}
return YES;
Expand Down
4 changes: 4 additions & 0 deletions Source/CBL_BlobStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,14 @@ - (instancetype) initWithStore: (CBL_BlobStore*)store {
if (![[NSFileManager defaultManager] createFileAtPath: _tempPath
contents: nil
attributes: nil]) {
Warn(@"CBL_BlobStoreWriter: Unable to create a temp file at %@", _tempPath);
return nil;
}
_out = [NSFileHandle fileHandleForWritingAtPath: _tempPath];
if (!_out) {
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath: _tempPath];
Warn(@"CBL_BlobStoreWriter: Unable to get a file handle for the temp file at "
"%@ (exists: %@)", _tempPath, (exists ? @"yes" : @"no"));
return nil;
}
CBLSymmetricKey* encryptionKey = _store.encryptionKey;
Expand Down

0 comments on commit bbd3b72

Please sign in to comment.