Fix for P130628-1037
[platform/framework/native/content.git] / src / FCnt_ContentManagerImpl.cpp
index 192d387..948c622 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include <aul/aul.h>
 #include <FBaseSysLog.h>
 #include <FAppApp.h>
 #include <FBaseInteger.h>
@@ -147,6 +148,7 @@ OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_
        SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
 
        _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
+       SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
 
        IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
        SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
@@ -212,6 +214,7 @@ OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_
                        SysLog(NID_CNT, "update_type is invalid.");
                        break;
                }
+               break;
        }
 
        case MEDIA_ITEM_DIRECTORY:
@@ -240,7 +243,17 @@ _ContentManagerImpl::_ContentManagerImpl(void)
 
 _ContentManagerImpl::~_ContentManagerImpl(void)
 {
-       int val = media_content_disconnect();
+       int val;
+
+       if (GetListener())
+       {
+               val = media_content_unset_db_updated_cb();
+               SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
+
+               SetListener(null);
+       }
+
+       val = media_content_disconnect();
        SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
 
        __isConnected = false;
@@ -521,6 +534,7 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
                        E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
 
        result r = E_SUCCESS;
+       bool isCopy = false;
 
        if (deleteSource) // move
        {
@@ -533,6 +547,8 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
                //  Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
                r = _FileImpl::Copy(sourcePath, destinationPath, true);
                SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
+
+               isCopy = true;
        }
 
        int val = 0;
@@ -597,9 +613,16 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
 CATCH:
        result saveResult = GetLastResult();
 
-       // If the destination file is made by this method, it should be deleted when error occurs.
-       r = _FileImpl::Remove(destinationPath);
-       SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
+       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));
+       }
 
        if (pMediaInfo != null)
        {
@@ -1074,13 +1097,32 @@ _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
        SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
                        "[E_INVALID_ARG] pContentData is null.");
 
-       // Exception : E_SUCCESS, E_INVALID_ARG
+       String mimeType(L"");
        String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
        result r = GetLastResult();
-       SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r, "[%s] Propagating.", GetErrorMessage(r));
+       if (IsFailed(r))
+       {
+               ClearLastResult();
+
+               SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
+
+               unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
+               SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+               char tempType[255] = {0, };
+               int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
+               SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
+                               "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
+
+               r = mimeType.Append(tempType);
+               SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+
+       }
 
        // If the content format is JPG and it has GPS data, it will be saved in database automatically.
-       if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG")
+       if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
        {
                SysLog(NID_CNT, "The format of content is jpg.");
 
@@ -1091,7 +1133,6 @@ _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
                        pContentData->longitude = pImageMetadata->GetLongitude();
 
                        delete pImageMetadata;
-                       pImageMetadata = null;
                }
        }
 
@@ -1901,7 +1942,7 @@ _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath,
                if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
                                contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
                {
-                       SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] %ls is not supported.", contentPath.GetPointer());
+                       SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
                        return false;
                }
        }