[Release] wrt-installer_0.1.53
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_remove_backup.cpp
index f23ea70..47e9cf4 100644 (file)
 #include <sys/stat.h>
 #include <string>
 #include <sstream>
-#include <dpl/wrt-dao-rw/widget_dao.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/foreach.h>
 #include <dpl/log/log.h>
 #include <dpl/assert.h>
 #include <dpl/utils/wrt_utility.h>
+#include <dpl/wrt-dao-rw/widget_dao.h>
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
@@ -42,32 +42,12 @@ TaskRemoveBackupFiles::TaskRemoveBackupFiles(InstallerContext& context) :
     DPL::TaskDecl<TaskRemoveBackupFiles>(this),
     m_context(context)
 {
-    AddStep(&TaskRemoveBackupFiles::StepDeleteDB);
-    AddStep(&TaskRemoveBackupFiles::StepRemoveBackupFiles);
-}
-
-void TaskRemoveBackupFiles::StepDeleteDB()
-{
-    LogInfo("Delete old widget DB");
-    Try
-    {
-        // If there is existing model, remove its database data
-        if (true == m_context.existingWidgetInfo.isExist) {
-            WidgetHandle old = m_context.existingWidgetInfo.existingHandle;
-            LogInfo("Unregistering widget...: " << old);
-            WidgetDAO::unregisterWidget(old);
-            LogInfo("Widget unregistered");
-        }
-    }
-    Catch(DPL::DB::SqlConnection::Exception::Base)
+    if (m_context.widgetConfig.packagingType !=
+            WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
     {
-        LogError("Failed to clean up old widget DB!");
-        ReThrowMsg(Exceptions::RemoveBackupFailed, "Database failure!");
+        AddStep(&TaskRemoveBackupFiles::StepRemoveBackupFiles);
     }
-
-    m_context.job->UpdateProgress(
-        InstallerContext::INSTALL_DELETE_OLD_DB,
-        "Backup widget db delete Finished");
+    AddStep(&TaskRemoveBackupFiles::StepDeleteBackupDB);
 }
 
 void TaskRemoveBackupFiles::StepRemoveBackupFiles()
@@ -88,13 +68,23 @@ void TaskRemoveBackupFiles::StepRemoveBackupFiles()
         LogDebug("Success to remove temp directory : " << tmp);
     } else {
         LogError("Failed to remove temp directory : " << tmp);
-        ThrowMsg(Exceptions::RemoveBackupFailed,
-                 "Error occurs during removing existing folder");
     }
+}
 
-    m_context.job->UpdateProgress(
-        InstallerContext::INSTALL_REMOVE_BACKUP_FILE,
-        "Backup widget file delete Finished");
+void TaskRemoveBackupFiles::StepDeleteBackupDB()
+{
+    LogDebug("StepDeleteBackupDB");
+    std::string oldAppid =
+        DPL::ToUTF8String(m_context.widgetConfig.tzAppid) + ".backup";
+
+    Try
+    {
+        WidgetDAO::unregisterWidget(DPL::FromUTF8String(oldAppid));
+    }
+    Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
+    {
+        LogError("Fail to delete old version db information");
+    }
 }
 
 } //namespace WidgetInstall