resolve TSAM-4264: subtract reserved size while getting free memory size 69/72669/2 accepted/tizen/common/20160603.150840 accepted/tizen/ivi/20160603.070447 accepted/tizen/mobile/20160603.070552 accepted/tizen/wearable/20160603.070502 submit/tizen/20160603.061107
authorKyeonghun Lee <kh9090.lee@samsung.com>
Thu, 2 Jun 2016 05:30:20 +0000 (14:30 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Fri, 3 Jun 2016 01:20:41 +0000 (10:20 +0900)
Change-Id: Ifeae3011b73be34e9d508e8ed273b94eea2b9c37
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
utils/MsgUtilStorage.cpp

index 7b8de31..defb17c 100755 (executable)
@@ -38,7 +38,10 @@ static int msgCntLimit[MSG_COUNT_LIMIT_MAILBOX_TYPE_MAX][MSG_COUNT_LIMIT_MSG_TYP
 
 using namespace std;
 
-#define ITERATION_SIZE 200
+#define CHECK_SIZE 1 * 1024 * 1024 * 1024
+#define RESERVE 100 * 1024 * 1024
+#define RESERVE_LITE 5 * 1024 * 1024
+
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
@@ -197,16 +200,25 @@ msg_error_t MsgStoCheckMsgCntFull(MsgDbHandler *pDbHandle, const MSG_MESSAGE_TYP
 
        boost::system::error_code ec;
        boost::filesystem::space_info si = boost::filesystem::space(TZ_SYS_HOME_PATH, ec);
+       long long int available = 0;
 
        if (ec) {
-               MSG_ERR("Faile to get space info [%s]", ec.message().c_str());
+               MSG_ERR("Failed to get space info [%s]", ec.message().c_str());
                return MSG_ERR_STORAGE_ERROR;
        } else {
-               MSG_DEBUG("Free space of storage is [%llu] Bytes.", si.available);
+               if (si.capacity < CHECK_SIZE)
+                       available = si.available - RESERVE_LITE;
+               else
+                       available = si.available - RESERVE;
+
+               if (available < 0)
+                       available = 0;
+
+               MSG_DEBUG("Free space of storage is [%llu] Bytes.", available);
 
-               if (si.available < SMS_MINIMUM_SPACE && pMsgType->mainType == MSG_SMS_TYPE)
+               if (available < SMS_MINIMUM_SPACE && pMsgType->mainType == MSG_SMS_TYPE)
                        err = MSG_ERR_MESSAGE_COUNT_FULL;
-               else if (si.available < MMS_MINIMUM_SPACE && pMsgType->mainType == MSG_MMS_TYPE)
+               else if (available < MMS_MINIMUM_SPACE && pMsgType->mainType == MSG_MMS_TYPE)
                        err = MSG_ERR_MESSAGE_COUNT_FULL;
        }
 
@@ -348,15 +360,24 @@ msg_error_t MsgStocheckMemoryStatus()
        msg_error_t err = MSG_SUCCESS;
        boost::system::error_code ec;
        boost::filesystem::space_info si = boost::filesystem::space(TZ_SYS_HOME_PATH, ec);
+       long long int available = 0;
 
        if (ec) {
-               MSG_ERR("Faile to get space info [%s]", ec.message().c_str());
+               MSG_ERR("Failed to get space info [%s]", ec.message().c_str());
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       MSG_DEBUG("Free space of storage is [%llu] Bytes.", si.available);
+       if (si.capacity < CHECK_SIZE)
+               available = si.available - RESERVE_LITE;
+       else
+               available = si.available - RESERVE;
+
+       if (available < 0)
+               available = 0;
+
+       MSG_DEBUG("Free space of storage is [%llu] Bytes.", available);
 
-       if (si.available < SMS_MINIMUM_SPACE)
+       if (available < SMS_MINIMUM_SPACE)
                err = MSG_ERR_MESSAGE_COUNT_FULL;
 
        MSG_DEBUG("Memory status =[%d]", err);