[Release] wrt-installer_0.1.85
[platform/framework/web/wrt-installer.git] / src / jobs / widget_uninstall / job_widget_uninstall.cpp
index 986ee29..70c6340 100644 (file)
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <pkg-manager/pkgmgr_signal.h>
 #include <app2ext_interface.h>
+#include <dpl/utils/path.h>
 
 using namespace WrtDB;
 
 namespace { //anonymous
 const char* REG_TIZEN_PKGID_PATTERN = "^[a-zA-Z0-9]{10}$";
 const int PKGID_LENTH = 10;
-const std::string PRELOAD_INSTALLED_PATH = "/usr/apps";
+const DPL::Utils::Path PRELOAD_INSTALLED_PATH("/usr/apps");
 
 bool checkDirectoryExist(const std::string& pkgId)
 {
-    std::string installPath =
-        std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
-        "/" + pkgId;
-
-    struct stat dirStat;
-    if ((stat(installPath.c_str(), &dirStat) == 0)) {
-        return true;
-    }
-    return false;
+    DPL::Utils::Path installPath(GlobalConfig::GetUserInstalledWidgetPath());
+    installPath /= pkgId;
+    return installPath.Exists();
 }
 }
 
@@ -106,7 +101,7 @@ JobWidgetUninstall::JobWidgetUninstall(
             m_context.locations = WidgetLocation(m_context.tzPkgid);
             m_context.locations->registerAppid(m_context.tzAppid);
             m_context.installedPath =
-                DPL::ToUTF8String(*dao.getWidgetInstalledPath());
+                DPL::Utils::Path(*dao.getWidgetInstalledPath());
 
             LogInfo("Widget model exists. App id : " << m_context.tzAppid);
 
@@ -150,7 +145,7 @@ WidgetStatus JobWidgetUninstall::getWidgetStatus(const std::string &id)
         LogDebug("Regcomp failed");
     }
     std::string pkgId;
-    std::string installPath;
+    DPL::Utils::Path installPath;
 
     Try {
         if ((regexec(&regx, id.c_str(),
@@ -163,16 +158,14 @@ WidgetStatus JobWidgetUninstall::getWidgetStatus(const std::string &id)
             LogDebug("Get appid from pkgid : " << appid);
             m_context.tzAppid = DPL::ToUTF8String(appid);
             WrtDB::WidgetDAOReadOnly dao(appid);
-            installPath = DPL::ToUTF8String(*dao.getWidgetInstalledPath());
+            installPath = DPL::Utils::Path(*dao.getWidgetInstalledPath());
         } else {
             pkgId = id.substr(0, PKGID_LENTH);
             WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(id));
             m_context.tzAppid = id;
-            installPath = DPL::ToUTF8String(*dao.getWidgetInstalledPath());
+            installPath = DPL::Utils::Path(*dao.getWidgetInstalledPath());
         }
-
-        if (0 == installPath.compare(0, PRELOAD_INSTALLED_PATH.length(),
-                    PRELOAD_INSTALLED_PATH)) {
+        if(installPath.isSubPath(PRELOAD_INSTALLED_PATH)){
             LogDebug("This widget is prealoded.");
         }
     } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {