Fix : The original content is restored again if CreateContent API fail 94/12894/1
authorSeokpil Park <seokpil.park@samsung.com>
Fri, 6 Sep 2013 07:49:13 +0000 (16:49 +0900)
committerSeokpil Park <seokpil.park@samsung.com>
Mon, 25 Nov 2013 11:40:10 +0000 (20:40 +0900)
Change-Id: Ib38edd152f7a6d58a965e3430a12a4722bc03d7b
Signed-off-by: Seokpil Park <seokpil.park@samsung.com>
src/FCnt_ContentManagerImpl.cpp

index 6d25bb4..07614cb 100644 (file)
@@ -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<char, CharDeleter> 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<char, CharDeleter> 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<char[]> 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<char, CharDeleter> 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);
        }