From ceff493b733b058f1775d5759dcfde2612cd17bb Mon Sep 17 00:00:00 2001 From: Seokpil Park Date: Fri, 6 Sep 2013 16:49:13 +0900 Subject: [PATCH] Fix : The original content is restored again if CreateContent API fail Change-Id: Ib38edd152f7a6d58a965e3430a12a4722bc03d7b Signed-off-by: Seokpil Park --- src/FCnt_ContentManagerImpl.cpp | 86 +++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/src/FCnt_ContentManagerImpl.cpp b/src/FCnt_ContentManagerImpl.cpp index 6d25bb4..07614cb 100644 --- a/src/FCnt_ContentManagerImpl.cpp +++ b/src/FCnt_ContentManagerImpl.cpp @@ -351,7 +351,20 @@ _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo) CATCH: // There are two steps(insert and update) for content registration. // If the update failed after inserting, the inserted data SHOULD be deleted from here. - val = media_info_delete_from_db(pStr.get()); + char* pTempMediaId = null; + unique_ptr pMediaId(null); + val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId); + if (pTempMediaId != null) + { + pMediaId.reset(pTempMediaId); + } + else + { + SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation."); + return UuId::GetInvalidUuId(); + } + + val = media_info_delete_from_db(pMediaId.get()); SysLog(NID_CNT, "The result of deletion from database[%d].", val); return UuId::GetInvalidUuId(); @@ -508,7 +521,20 @@ CATCH: if (pMediaInfo != null) { - val = media_info_delete_from_db(pStr.get()); + char* pTempMediaId = null; + unique_ptr pMediaId(null); + val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId); + if (pTempMediaId != null) + { + pMediaId.reset(pTempMediaId); + } + else + { + SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation."); + return UuId::GetInvalidUuId(); + } + + val = media_info_delete_from_db(pMediaId.get()); SysLog(NID_CNT, "The result of deletion from database[%d].", val); } @@ -532,21 +558,8 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer()); - result r = E_SUCCESS; - bool isCopy = false; - - if (deleteSource) // move - { - r = _FileImpl::Move(sourcePath, destinationPath); - SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Moving the file failed.", GetErrorMessage(r)); - } - else // copy - { - r = _FileImpl::Copy(sourcePath, destinationPath, true); - SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r)); - - isCopy = true; - } + result r = _FileImpl::Copy(sourcePath, destinationPath, true); + SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r)); int val = 0; ContentId contentId; @@ -651,25 +664,42 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r, "[%s] SaveDataToDatabase failed.", GetErrorMessage(r)); + if (deleteSource) + { + unique_ptr pContentPath(_StringConverter::CopyToCharArrayN(sourcePath)); + SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY, "[%s] pContentPath is null.", GetErrorMessage(E_OUT_OF_MEMORY)); + + r = _FileImpl::Remove(sourcePath); + SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Remove operation.", GetErrorMessage(r)); + + val = media_content_scan_file(pContentPath.get()); + SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "Failed to perform media_content_scan_file[%d].", val); + } + return contentId; CATCH: result saveResult = GetLastResult(); - if (isCopy) - { - r = _FileImpl::Remove(destinationPath); - SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r)); - } - else - { - r = _FileImpl::Move(destinationPath, sourcePath); - SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r)); - } + r = _FileImpl::Remove(destinationPath); + SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r)); if (pMediaInfo != null) { - val = media_info_delete_from_db(pStr.get()); + char* pTempMediaId = null; + unique_ptr pMediaId(null); + val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId); + if (pTempMediaId != null) + { + pMediaId.reset(pTempMediaId); + } + else + { + SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation."); + return UuId::GetInvalidUuId(); + } + + val = media_info_delete_from_db(pMediaId.get()); SysLog(NID_CNT, "The result of deletion from database[%d].", val); } -- 2.7.4