Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / system / FSys_RuntimeInfoImpl.cpp
index a1e4d88..b74a1c4 100644 (file)
@@ -47,7 +47,6 @@
 #include "FSys_EnvironmentImpl.h"
 #include "FSys_RuntimeInfoImpl.h"
 #include "FSys_RuntimeClient.h"
-#include "FSys_RuntimeClientEx.h"
 
 using namespace Tizen::App;
 using namespace Tizen::Base;
@@ -379,10 +378,13 @@ _RuntimeInfoImpl::GetDirectorySize(const char* path)
                return 0;
        }
 
-       char command[512] = {0,};
-       char fileName[512] = {0,};
+       char* pCommand = null;
+       char* pFileName = null;
+       int fileLength = 0;
+       int commandLength = 0;
        long long size = 0;
        int ret = 0;
+       FILE* pFile = null;
 
        Tizen::App::App* pApp = Tizen::App::App::GetInstance();
        if(pApp == null)
@@ -391,80 +393,65 @@ _RuntimeInfoImpl::GetDirectorySize(const char* path)
        }
 
        String appId(pApp->GetAppId());
-       unique_ptr <char> appIdPath(_StringConverter::CopyToCharArrayN(appId));
+       unique_ptr <char[]> appIdPath(_StringConverter::CopyToCharArrayN(appId));
 
-       ret = sprintf(fileName, "/tmp/size_of_directory_%s.tmp", appIdPath.get());
-       if(ret < 1)
-       {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write file path.");
-               return 0;
-       }
+       fileLength = strlen(appIdPath.get()) + 29;
+       pFileName = (char*)malloc(fileLength);
+       SysTryCatch(NID_SYS, pFileName, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is not enough memory.");
 
-       ret = sprintf(command, "rm -rf %s", fileName);
-       if(ret < 1)
-       {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write remove command.");
-               return 0;
-       }
+       ret = sprintf(pFileName, "/tmp/size_of_directory_%s.tmp", appIdPath.get());
+       SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write file path.");
 
-       ret = system(command);
+       commandLength = strlen(pFileName) + 8;
+       pCommand = (char*) malloc(commandLength);
+       SysTryCatch(NID_SYS, pCommand, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is not enough memory.");
 
+       ret = sprintf(pCommand, "rm -rf %s", pFileName);
+       SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write remove pCommand.");
+
+       ret = system(pCommand);
        if(ret == -1)
        {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute pCommand[%s].", pCommand);
        }
+       free(pCommand);
+       pCommand = null;
 
-       ret = sprintf(command, "du -skb -P %s >> %s", path, fileName);
-       if(ret < 1)
-       {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write du command.");
-               return 0;
-       }
+       commandLength = strlen(pFileName) + strlen(path) + 16;
+       pCommand = (char*)malloc(commandLength);
+       SysTryCatch(NID_SYS, pCommand, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is not enough memory.");
 
-       ret = system(command);
-       if(ret == -1)
-       {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
-               return 0;
-       }
+       ret = sprintf(pCommand, "du -skb -P %s >> %s", path, pFileName);
+       SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write du pCommand.");
 
-       FILE* pFile = null;
-       pFile = fopen(fileName, "r");
-       if(pFile == null)
-       {
-               return 0;
-       }
+       ret = system(pCommand);
+       SysTryCatch(NID_SYS, ret != -1, E_SYSTEM, E_SYSTEM, "It is failed to execute pCommand[%s].", pCommand);
+
+       pFile = fopen(pFileName, "r");
+       SysTryCatch(NID_SYS, pFile != null, E_SYSTEM, E_SYSTEM, "It is failed to read file [%s].", pFileName);
 
        ret = fscanf(pFile, "%lld", &size);
-       if(ret < 1)
-       {
-               if(pFile != null)
-               {
-                       fclose(pFile);
-               }
+       SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to read file [%s].", pFileName);
 
-               return 0;
-       }
+       ret = sprintf(pCommand, "rm -rf %s", pFileName);
+       SysTryCatch(NID_SYS, ret > 0, E_SYSTEM, E_SYSTEM, "It is failed to write remove pCommand.");
+
+       ret = system(pCommand);
+       SysTryCatch(NID_SYS, ret != -1, E_SYSTEM, E_SYSTEM, "It is failed to execute pCommand[%s].", pCommand);
 
-       if(pFile != null)
+CATCH:
+       if (pFileName)
        {
-               fclose(pFile);
+               free(pFileName);
        }
-
-       ret = sprintf(command, "rm -rf %s", fileName);
-       if(ret < 1)
+       if (pCommand)
        {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write remove command.");
-               return 0;
+               free(pCommand);
        }
-
-       ret = system(command);
-       if(ret == -1)
+       if (pFile)
        {
-               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+               fclose(pFile);
        }
-
-
        return size;
 }
 
@@ -793,19 +780,8 @@ _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetLonglongAsyncR
        SysLog(NID_SYS, "%ls", directoryPath.GetPointer());
        if(r == E_SUCCESS)
        {
-//             if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_runtime") == true)
-               {
-                       SysLog(NID_SYS, "Runtime is serviced by common-service.");
-                       _RuntimeClientEx* pRuntimeClientEx = _RuntimeClientEx::GetInstance();
-                       pRuntimeClientEx->GetDirectorySizeValueAsync(directoryPath, listener);
-               }
-/*             else
-               {
-                       SysLog(NID_SYS, "Runtime is serviced by app-service.");
-                       _RuntimeClient* pRuntimeClient = _RuntimeClient::GetInstance();
-                       pRuntimeClient->GetDirectorySizeValueAsync(directoryPath, listener);
-               }
-*/
+               _RuntimeClient* pRuntimeClient = _RuntimeClient::GetInstance();
+               pRuntimeClient->GetDirectorySizeValueAsync(directoryPath, listener);
        }
 
        return r;