[UpdateApplication] Added step for update installation 17/38517/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 24 Mar 2015 17:16:57 +0000 (18:16 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 24 Apr 2015 08:40:03 +0000 (01:40 -0700)
Tizen-JIRA: TC-2482

Change-Id: Ib0b2a60ba003fa81c9eaeb7c4df16fb97bdf7c21

src/common/CMakeLists.txt
src/common/step/step_update_app.cc [new file with mode: 0644]
src/common/step/step_update_app.h [new file with mode: 0644]

index ab76581..3a4244d 100644 (file)
@@ -18,6 +18,7 @@ SET(SRCS
   step/step_revoke_security.cc
   step/step_register_security.cc
   step/step_unregister_app.cc
+  step/step_update_app.cc
   step/step_update_security.cc
 )
 # Target - definition
diff --git a/src/common/step/step_update_app.cc b/src/common/step/step_update_app.cc
new file mode 100644 (file)
index 0000000..b3f7381
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_update_app.h"
+
+#include <pkgmgr-info.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <boost/filesystem.hpp>
+#include <cassert>
+#include <cstdio>
+#include <cstring>
+#include <string>
+
+#include "utils/file_util.h"
+
+namespace bf = boost::filesystem;
+
+namespace {
+
+const char* const kAppinstTags[] = {"removable=true", nullptr, };
+
+bool UpgradeManifestInformation(uid_t uid, const bf::path& xml_path) {
+  int ret = uid != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
+       pkgmgr_parser_parse_usr_manifest_for_upgrade(
+           xml_path.string().c_str(), uid,
+           const_cast<char* const*>(kAppinstTags)) :
+       pkgmgr_parser_parse_usr_manifest_for_upgrade(
+           xml_path.string().c_str(), uid,
+           const_cast<char* const*>(kAppinstTags));
+  return !ret;
+}
+
+}  // anonymous namespace
+
+namespace common_installer {
+namespace update_app {
+
+Step::Status StepUpdateApplication::precheck() {
+  if (context_->xml_path.get().empty()) {
+    LOG(ERROR) << "Xml path is empty";
+    return Status::ERROR;
+  }
+  return Status::OK;
+}
+
+Step::Status StepUpdateApplication::process() {
+  if (!UpgradeManifestInformation(context_->uid.get(),
+      context_->xml_path.get())) {
+    LOG(ERROR) << "Cannot upgrade manifest for application";
+    return Status::ERROR;
+  }
+
+  LOG(INFO) << "Successfully install the application";
+  return Status::OK;
+}
+
+Step::Status StepUpdateApplication::clean() {
+  return Status::OK;
+}
+
+Step::Status StepUpdateApplication::undo() {
+  if (!UpgradeManifestInformation(context_->uid.get(),
+      context_->backup_xml_path.get())) {
+    LOG(ERROR) << "Cannot revert manifest for application";
+    return Status::ERROR;
+  }
+  LOG(INFO) << "Database reverted successfully";
+  return Status::OK;
+}
+
+}  // namespace update_app
+}  // namespace common_installer
diff --git a/src/common/step/step_update_app.h b/src/common/step/step_update_app.h
new file mode 100644 (file)
index 0000000..c57cc61
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_UPDATE_APP_H_
+#define COMMON_STEP_STEP_UPDATE_APP_H_
+
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "utils/logging.h"
+
+namespace common_installer {
+namespace update_app {
+
+class StepUpdateApplication : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override;
+  Status undo() override;
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(UpdateApplication)
+};
+
+}  // namespace update_app
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_UPDATE_APP_H_