From 94f510747560f2f603175237714485ffb8718564 Mon Sep 17 00:00:00 2001 From: Pasin Suriyentrakorn Date: Wed, 8 Apr 2015 16:52:01 -0700 Subject: [PATCH] Handle unable to create a blob store writer for the attachment - Return AttachmentError when cannot create a blob store writer for the attachment. - Add warning messages to pin point where the issue is. --- Source/CBLMultipartDocumentReader.m | 11 +++++++++-- Source/CBL_BlobStore.m | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/CBLMultipartDocumentReader.m b/Source/CBLMultipartDocumentReader.m index e82fbd96f..0fc041b27 100644 --- a/Source/CBLMultipartDocumentReader.m +++ b/Source/CBLMultipartDocumentReader.m @@ -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; diff --git a/Source/CBL_BlobStore.m b/Source/CBL_BlobStore.m index 40f160151..dc855ca7c 100644 --- a/Source/CBL_BlobStore.m +++ b/Source/CBL_BlobStore.m @@ -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;