[Release] wrt-installer_0.1.55
[framework/web/wrt-installer.git] / src / jobs / widget_uninstall / task_remove_files.cpp
old mode 100644 (file)
new mode 100755 (executable)
index d7c3157..709b4a5
  * @brief   Implementation file for uninstaller task for removing widget files
  */
 
+#include <unistd.h>
 #include <widget_uninstall/task_remove_files.h>
 #include <widget_uninstall/job_widget_uninstall.h>
 #include <widget_uninstall/uninstaller_context.h>
+#include <widget_uninstall/widget_uninstall_errors.h>
 #include <dpl/wrt-dao-rw/widget_dao.h>
 #include <dpl/wrt-dao-ro/widget_config.h>
 #include <dpl/wrt-dao-ro/vconf_config.h>
 #include <dpl/assert.h>
+#include <dpl/exception.h>
 #include <dpl/utils/wrt_utility.h>
 #include <ail.h>
 #include <pkgmgr/pkgmgr_parser.h>
@@ -37,7 +40,6 @@
 
 namespace Jobs {
 namespace WidgetUninstall {
-
 using namespace WrtDB;
 
 namespace {
@@ -48,12 +50,7 @@ TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
     DPL::TaskDecl<TaskRemoveFiles>(this),
     m_context(context)
 {
-    if (!m_context.isExternalWidget) {
-        AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
-    } else {
-        AddStep(&TaskRemoveFiles::StepRemoveExternalWidget);
-    }
-    //AddStep(&TaskRemoveFiles::StepRemoveDesktop);
+    AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory);
     AddStep(&TaskRemoveFiles::StepRemoveManifest);
     AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
     AddStep(&TaskRemoveFiles::StepRemoveVconf);
@@ -61,22 +58,41 @@ TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
 }
 
 TaskRemoveFiles::~TaskRemoveFiles()
-{
-}
+{}
 
 void TaskRemoveFiles::StepRemoveInstallationDirectory()
 {
     LogInfo("StepRemoveInstallationDirectory started");
+    Try {
+        if (APP2EXT_SD_CARD !=
+                app2ext_get_app_location(m_context.tzPkgid.c_str()))
+        {
+            LogDebug("Removing directory");
+            m_context.removeStarted = true;
+            if (!WrtUtilRemove(m_context.installedPath)) {
+                LogError("Removing widget installation directory failed : " <<
+                        m_context.installedPath);
+            }
+            std::string dataDir = m_context.locations->getUserDataRootDir();
+            if (!WrtUtilRemove(dataDir)) {
+                LogWarning(dataDir + " is already removed");
+            }
+        } else {
+            LogDebug("Removing sdcard directory");
+            Try {
+                WidgetInstallToExtSingleton::Instance().initialize(m_context.tzPkgid);
+                WidgetInstallToExtSingleton::Instance().uninstallation();
+                WidgetInstallToExtSingleton::Instance().deinitialize();
+            }
+            Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
+            {
+                Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
+                        RemoveFilesFailed);
+            }
+        }
+    } Catch(Exception::RemoveFilesFailed) {
+        ThrowMsg(Exceptions::RemoveFileFailure, "Cann't remove directory");
 
-    m_context.removeStarted = true;
-    std::string widgetDir =
-        m_context.locations->getPackageInstallationDir();
-    if(!WrtUtilRemove(widgetDir)){
-        LogWarning("Removing widget installation directory failed");
-    }
-    std::string dataDir = m_context.locations->getUserDataRootDir();
-    if(!WrtUtilRemove(dataDir)){
-        LogWarning(dataDir + " is already removed");
     }
     m_context.job->UpdateProgress(
         UninstallerContext::UNINSTALL_REMOVE_WIDGETDIR,
@@ -92,114 +108,76 @@ void TaskRemoveFiles::StepRemoveFinished()
         "Widget remove steps Finished");
 }
 
-void TaskRemoveFiles::StepRemoveDesktop()
-{
-    std::ostringstream desktopFile;
-
-    desktopFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
-    desktopFile << m_context.pkgname << ".desktop";
-
-    unlink(desktopFile.str().c_str());
-
-    ail_appinfo_h ai = NULL;
-    ail_error_e ret;
-
-    const char* package = m_context.pkgname.c_str();
-    LogDebug("ail delete : " << package);
-
-    ret = ail_package_get_appinfo(package, &ai);
-    if (ai) {
-        ail_package_destroy_appinfo(ai);
-    }
-
-    if (AIL_ERROR_OK == ret) {
-        if ( 0 > ail_desktop_remove(package)) {
-            LogWarning("Failed to remove ail information : " << package);
-        }
-    }
-
-    m_context.job->UpdateProgress(
-        UninstallerContext::UNINSTALL_REMOVE_DESKTOP,
-        "Widget remove desktop Finished");
-}
-
 void TaskRemoveFiles::StepRemoveManifest()
 {
     std::ostringstream manifest_name;
-    manifest_name << m_context.pkgname << ".xml";
+    manifest_name << m_context.tzPkgid << ".xml";
     std::ostringstream destFile;
-    destFile << "/opt/share/packages" << "/"; //TODO constant with path
+    const std::string PRELOAD_INSTALLED_PATH = "/usr/apps";
+    if (0 == (m_context.installedPath).compare(0, PRELOAD_INSTALLED_PATH.length(),
+                PRELOAD_INSTALLED_PATH)) {
+        LogDebug("This widget is prealoded.");
+        destFile << "/usr/share/packages" << "/"; //TODO constant with path
+    } else {
+        destFile << "/opt/share/packages" << "/"; //TODO constant with path
+    }
     destFile << manifest_name.str();
-    int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(destFile.str().c_str(), NULL);
+    int ret1 = pkgmgr_parser_parse_manifest_for_uninstallation(
+            destFile.str().c_str(), NULL);
     int ret2 = unlink(destFile.str().c_str());
-    if(ret1 != 0)
-    {
+    if (ret1 != 0) {
         LogWarning("Manifest file failed to parse for uninstallation");
     }
-    if(ret2 != 0)
-    {
+    if (ret2 != 0) {
         LogWarning("No manifest file found: " << destFile.str());
-    }
-    else
-    {
+    } else {
         LogDebug("Manifest file removed: " << destFile.str());
     }
 }
 
 void TaskRemoveFiles::StepRemoveExternalLocations()
 {
-    WidgetDAO dao(m_context.locations->getPkgname());
-    LogDebug("Removing external locations:");
-    WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
-    FOREACH(path, externalPaths)
-    {
-        if(WrtUtilFileExists(*path))
-        {
-            LogDebug("  -> " << *path);
-            int ret = remove(path->c_str());
-            if (ret != 0) {
-                LogError("Failed to remove the file: " << path->c_str() << " with error: " << strerror(errno));
-            }
-        }
-        else if(WrtUtilDirExists(*path))
+    if (!m_context.removeAbnormal) {
+        WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
+        LogDebug("Removing external locations:");
+        WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
+        FOREACH(path, externalPaths)
         {
-            LogDebug("  -> " << *path);
-            if(!WrtUtilRemove(*path)){
-                Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::RemoveFilesFailed);
+            if (WrtUtilFileExists(*path)) {
+                LogDebug("  -> " << *path);
+                int ret = remove(path->c_str());
+                if (ret != 0) {
+                    LogError(
+                            "Failed to remove the file: " << path->c_str() <<
+                            " with error: " << strerror(errno));
+                }
+            } else if (WrtUtilDirExists(*path)) {
+                LogDebug("  -> " << *path);
+                if (!WrtUtilRemove(*path)) {
+                    Throw(
+                            Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
+                            RemoveFilesFailed);
+                }
+            } else {
+                LogWarning("  -> " << *path << "(no such a path)");
             }
         }
-        else
-        {
-            LogWarning("  -> " << *path << "(no such a path)");
-        }
+        dao.unregisterAllExternalLocations();
     }
-    dao.unregisterAllExternalLocations();
 }
 
 void TaskRemoveFiles::StepRemoveVconf()
 {
-    std::string key =
-        WrtDB::VconfConfig::GetVconfKeyRootPath(
-            m_context.locations->getPkgname());
-    if(vconf_unset_recursive(key.c_str())) {
-        LogError("Fail to unset vconf file");
-    } else {
-        LogDebug("vconf file is removed");
-    }
-}
-
-void TaskRemoveFiles::StepRemoveExternalWidget()
-{
-    Try {
-        WidgetInstallToExtSingleton::Instance().initialize(m_context.pkgname);
-        WidgetInstallToExtSingleton::Instance().uninstallation();
-        WidgetInstallToExtSingleton::Instance().deinitialize();
-    }
-    Catch (WidgetInstallToExt::Exception::ErrorInstallToExt)
-    {
-        Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::RemoveFilesFailed);
+    if (!m_context.removeAbnormal) {
+        std::string key =
+            WrtDB::VconfConfig::GetVconfKeyRootPath(DPL::FromUTF8String(m_context.
+                        tzAppid));
+        if (vconf_unset_recursive(key.c_str())) {
+            LogError("Fail to unset vconf file");
+        } else {
+            LogDebug("vconf file is removed");
+        }
     }
 }
-
 } //namespace WidgetUninstall
 } //namespace Jobs