Modify IsAppInstalled() API
[platform/framework/native/appfw.git] / src / io / FIo_RegistryCore.cpp
index 03882c8..aa40372 100644 (file)
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <new>
 #include <unique_ptr.h>
+#include <string.h>
+#include <errno.h>
 
 #include <FBaseInteger.h>
 #include <FBaseDouble.h>
@@ -38,6 +40,7 @@
 
 #include <FBase_StringConverter.h>
 #include <FBase_LocalizedNumParser.h>
+#include <FBase_NativeError.h>
 #include <FApp_AppInfo.h>
 #include "FIo_FileImpl.h"
 #include "FIo_NormalRegistry.h"
@@ -231,7 +234,7 @@ _RegistryCore::Parse(void)
                        }
 
                        r = _RegistryCore::AddSection(_sectionList, sectionName);
-                       SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+                       SysTryCatch(NID_IO, !IsFailed(r) || r == E_SECTION_ALREADY_EXIST, , r, "[%s] Propagating to caller...", GetErrorMessage(r));
                }
                else    // not a section.. but may belongs to a section (entry)
                {
@@ -304,7 +307,10 @@ _RegistryCore::Parse(void)
                                                   "[E_PARSING_FAILED] Entry name could not be parsed.");
                        }
 
-                       line.SubString(firstTokenPos + 1, entryVal); // extract entry value
+                       if (line.GetLength() > firstTokenPos + 1)
+                       {
+                               line.SubString(firstTokenPos + 1, entryVal); // extract entry value
+                       }
 
                        // check if entry value contains invalid chars
                        pEntryValue.reset(_StringConverter::CopyToCharArrayN(entryVal));
@@ -408,6 +414,7 @@ _RegistryCore::AddSection(const String& sectionName)
 
        if (sectionFound == true)
        {
+               SysLog(NID_IO, "[E_SECTION_ALREADY_EXIST] The registry file has the duplicated section name.");
                return E_SECTION_ALREADY_EXIST;
        }
 
@@ -1031,8 +1038,9 @@ _RegistryCore::PrepareToWrite(void)
        if (_sectionList.GetCount() == 0)
        {
                unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(_regPath));
-               truncate(pFilePath.get(), 0);
-
+               int res = truncate(pFilePath.get(), 0);
+               SysTryReturnResult(NID_IO, res == 0, __ConvertNativeErrorToResult(errno),
+                               "Failed to truncate. errno: %d (%s)", errno, strerror(errno));
                return E_SUCCESS;
        }
 
@@ -1562,6 +1570,7 @@ _RegistryCore::AddSection(LinkedList& sectionList, const String& sectionName)
 
        if (sectionFound == true)
        {
+               SysLog(NID_IO, "[E_SECTION_ALREADY_EXIST] The registry file has the duplicated section name.");
                return E_SECTION_ALREADY_EXIST;
        }