Skip to content

Commit

Permalink
Handle unable to create a blob store writer for the attachment
Browse files Browse the repository at this point in the history
- Return AttachmentError when cannot  create a blob store writer for the attachment.

- Add warning messages to pin point where the issue is.
  • Loading branch information
pasin committed Apr 8, 2015
1 parent fcbed11 commit 94f5107
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 94f5107

Please sign in to comment.