[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_pkg_info_update.cpp
  *    See the License for the specific language governing permissions and
  *    limitations under the License.
  */
-/*
- * @file    task_certificates.cpp
- * @author  Leerang Song(leerang.song@samsung.com)
+/**
+ * @file    task_pkg_info_update.cpp
+ * @author  Soyoung Kim (sy037.kim@samsung.com)
  * @version 1.0
- * @brief   Implementation file for installer task certificates
+ * @brief   Implementation file for installer task information about package
+ * update
  */
-#include <widget_install/task_certificates.h>
-#include <widget_install/widget_install_context.h>
-#include <widget_install/widget_install_errors.h>
-#include <widget_install/job_widget_install.h>
-#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
-#include <pkgmgr_installer.h>
-#include <vcore/CryptoHash.h>
+#include "task_pkg_info_update.h"
+
+#include <unistd.h>
+#include <string>
 
+#include <fstream>
 #include <dpl/log/log.h>
-#include <dlog.h>
-#include <sstream>
+#include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/foreach.h>
 #include <dpl/sstream.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <pkgmgr_installer.h>
+#include <pkgmgr/pkgmgr_parser.h>
+#include <pkgmgr-info.h>
+#include <vcore/CryptoHash.h>
+
+#include <widget_install/job_widget_install.h>
+#include <widget_install/widget_install_context.h>
+#include <widget_install/widget_install_errors.h>
 
 using namespace WrtDB;
 
+namespace {
+}
+
 namespace Jobs {
 namespace WidgetInstall {
-TaskCertificates::TaskCertificates(InstallerContext& context) :
-    DPL::TaskDecl<TaskCertificates>(this),
-    m_context(context),
-    m_pkgHandle(NULL)
+TaskPkgInfoUpdate::TaskPkgInfoUpdate(InstallerContext& context) :
+    DPL::TaskDecl<TaskPkgInfoUpdate>(this),
+    m_context(context)
+{
+    AddStep(&TaskPkgInfoUpdate::StartStep);
+    AddStep(&TaskPkgInfoUpdate::StepPkgInfo);
+    AddStep(&TaskPkgInfoUpdate::StepSetCertiInfo);
+    AddStep(&TaskPkgInfoUpdate::EndStep);
+    AddStep(&TaskPkgInfoUpdate::StepSetEndofInstallation);
+
+    AddAbortStep(&TaskPkgInfoUpdate::StepAbortCertiInfo);
+    AddAbortStep(&TaskPkgInfoUpdate::stepAbortParseManifest);
+}
+
+void TaskPkgInfoUpdate::StepPkgInfo()
 {
-    AddStep(&TaskCertificates::StepSetCertiInfo);
-    AddAbortStep(&TaskCertificates::StepAbortCertiInfo);
+    int code = 0;
+    char* updateTags[3] = {NULL, };
+
+    if (!m_context.mode.removable) {
+        updateTags[0] = "preload=false";
+        updateTags[1] = "removable=false";
+        updateTags[2] = NULL;
+
+    }
+
+    if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
+        m_manifest += "/usr/share/packages/";
+    } else {
+        m_manifest += "/opt/share/packages/";
+    }
+    m_manifest += DPL::ToUTF8String(m_context.widgetConfig.tzPkgid) + ".xml";
+    LogDebug("manifest file : " << m_manifest);
+
+    if (m_context.isUpdateMode || (
+                m_context.mode.rootPath == InstallMode::RootPath::RO
+                && m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
+                && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
+
+        if (m_context.widgetConfig.packagingType != PKG_TYPE_HYBRID_WEB_APP) {
+            code = pkgmgr_parser_parse_manifest_for_upgrade(
+                    m_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
+
+            if (code != 0) {
+                LogError("Manifest parser error: " << code);
+                ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
+            }
+        }
+    } else {
+        code = pkgmgr_parser_parse_manifest_for_installation(
+                m_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
+
+        if (code != 0) {
+            LogError("Manifest parser error: " << code);
+            ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
+        }
+    }
+
+    m_context.job->UpdateProgress(
+            InstallerContext::INSTALL_PKGINFO_UPDATE,
+            "Manifest Update Finished");
+    LogDebug("Manifest parsed");
 }
 
-void TaskCertificates::StepSetCertiInfo()
+void TaskPkgInfoUpdate::StepSetCertiInfo()
 {
     LogDebug("StepSetCertiInfo");
 
@@ -74,17 +139,14 @@ void TaskCertificates::StepSetCertiInfo()
     if (pkgmgr_installer_destroy_certinfo_set_handle(m_pkgHandle) < 0) {
         LogError("pkgmgrInstallerDestroyCertinfoSetHandle fail");
     }
-
-    m_context.job->UpdateProgress(
-            InstallerContext::INSTALL_SET_CERTINFO,
-            "Save certinfo to pkgmgr");
 }
 
-void TaskCertificates::SetCertiInfo(CertificateSource source)
+void TaskPkgInfoUpdate::SetCertiInfo(int source)
 {
     LogDebug("Set CertiInfo to pkgmgr : " << source);
     CertificateChainList certificateChainList;
-    m_context.widgetSecurity.getCertificateChainList(certificateChainList, source);
+    m_context.widgetSecurity.getCertificateChainList(certificateChainList,
+            (CertificateSource)source);
 
     FOREACH(it, certificateChainList)
     {
@@ -169,7 +231,7 @@ void TaskCertificates::SetCertiInfo(CertificateSource source)
     }
 }
 
-void TaskCertificates::StepAbortCertiInfo()
+void TaskPkgInfoUpdate::StepAbortCertiInfo()
 {
     if ((pkgmgr_installer_delete_certinfo(
              const_cast<char*>(DPL::ToUTF8String(
@@ -179,5 +241,44 @@ void TaskCertificates::StepAbortCertiInfo()
         LogError("pkgmgr_installer_delete_certinfo fail");
     }
 }
+
+void TaskPkgInfoUpdate::StartStep()
+{
+    LogDebug("--------- <TaskPkgInfoUpdate> : START ----------");
+}
+
+void TaskPkgInfoUpdate::EndStep()
+{
+    m_context.job->UpdateProgress(
+            InstallerContext::INSTALL_SET_CERTINFO,
+            "Save certinfo to pkgmgr");
+
+    LogDebug("--------- <TaskPkgInfoUpdate> : END ----------");
+}
+
+void TaskPkgInfoUpdate::stepAbortParseManifest()
+{
+    LogError("[Parse Manifest] Abroting....");
+
+    int code = pkgmgr_parser_parse_manifest_for_uninstallation(
+            m_manifest.c_str(), NULL);
+
+    if (0 != code) {
+        LogWarning("Manifest parser error: " << code);
+        ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
+    }
+    int ret = unlink(m_manifest.c_str());
+    if (0 != ret) {
+        LogWarning("No manifest file found: " << m_manifest);
+    }
+}
+
+void TaskPkgInfoUpdate::StepSetEndofInstallation()
+{
+    m_context.job->UpdateProgress(
+        InstallerContext::INSTALL_END,
+        "End installation");
+}
+
 } //namespace WidgetInstall
 } //namespace Jobs