Remove UpdateTepInfoInPkgmgr function. Fix preserving tep file through update 14/64814/4
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 5 Apr 2016 12:05:39 +0000 (14:05 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Thu, 7 Apr 2016 09:32:42 +0000 (02:32 -0700)
Submit together:
  https://review.tizen.org/gerrit/64808
  https://review.tizen.org/gerrit/64809
  https://review.tizen.org/gerrit/64814

Change-Id: Ib4a7214246f806fc57a382ed0e03e5fe0f8f3f27

src/common/pkgmgr_registration.cc
src/common/pkgmgr_registration.h
src/common/step/configuration/step_parse_manifest.cc
src/common/step/filesystem/step_copy_tep.cc
src/common/step/pkgmgr/step_update_tep.cc
src/common/step/pkgmgr/step_update_tep.h

index 4f89154..f741868 100644 (file)
@@ -166,22 +166,6 @@ bool RegisterAppInPkgmgr(manifest_x* manifest,
   return true;
 }
 
-bool UpdateTepInfoInPkgmgr(const bf::path& tep_path, const std::string& pkgid,
-                        uid_t uid, RequestMode request_mode) {
-  int ret = request_mode != RequestMode::GLOBAL ?
-        pkgmgr_parser_usr_update_tep(
-            pkgid.c_str(), tep_path.string().c_str(), uid) :
-        pkgmgr_parser_update_tep(
-            pkgid.c_str(), tep_path.string().c_str());
-
-  if (ret != 0) {
-    LOG(ERROR) << "Failed to upgrade tep info: " << pkgid;
-    return false;
-  }
-
-  return true;
-}
-
 bool UpgradeAppInPkgmgr(manifest_x* manifest,
                         const bf::path& xml_path,
                         const std::string& pkgid,
@@ -263,6 +247,25 @@ std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
   return old_author_certificate;
 }
 
+std::string QueryTepPath(const std::string& pkgid, uid_t uid) {
+  pkgmgrinfo_pkginfo_h package_info;
+  if (pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), uid, &package_info)
+      != PMINFO_R_OK)
+    return false;
+  char* tep_name = nullptr;
+  int ret = pkgmgrinfo_pkginfo_get_tep_name(package_info, &tep_name);
+  if (ret != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_tep_name failed with error: "
+               << ret;
+    pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
+    return {};
+  }
+  std::string tep_name_value;
+  if (tep_name)
+    tep_name_value = tep_name;
+  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
+  return tep_name_value;
+}
 
 bool QueryAppidsForPkgId(const std::string& pkg_id,
                          std::vector<std::string>* result, uid_t uid) {
index c54803f..5549144 100644 (file)
@@ -56,22 +56,6 @@ bool UpgradeAppInPkgmgr(manifest_x* manifest,
                         RequestMode request_mode);
 
 /**
- * \brief Adapter interface for external PkgMgr module used for updating
- *        tep info about package within pkgmgr
- *
- * \param tep_path path of tep file
- * \param pkgid package pkgid
- * \param uid user id
- * \param request_mode current request mode
- *
- * \return true if success
- */
-bool UpdateTepInfoInPkgmgr(const boost::filesystem::path& tep_path,
-                           const std::string& pkgid,
-                           uid_t uid,
-                           RequestMode request_mode);
-
-/**
  * \brief Adapter interface for external PkgMgr module used for deregistering
  *        package into pkgmgr
  *
@@ -102,6 +86,16 @@ std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
 
 /**
  * \brief Adapter interface for external PkgMgr module used for getting
+ *        tizen extension package path for given package
+ *
+ * @param pkgid package id
+ * @param uid user id
+ * @return path or empty
+ */
+std::string QueryTepPath(const std::string& pkgid, uid_t uid);
+
+/**
+ * \brief Adapter interface for external PkgMgr module used for getting
  *        list of appids for given package
  *
  * \param pkg_id[in] package pkgid
index cc07e91..2276f60 100644 (file)
@@ -33,6 +33,7 @@
 #include "common/app_installer.h"
 #include "common/backup_paths.h"
 #include "common/installer_context.h"
+#include "common/pkgmgr_registration.h"
 #include "common/step/step.h"
 #include "common/utils/glist_range.h"
 
@@ -763,8 +764,13 @@ Step::Status StepParseManifest::process() {
     return Step::Status::PARSE_ERROR;
   }
 
-  if (!context_->tep_path.get().empty())
-    manifest->tep_name = strdup(context_->tep_path.get().c_str());
+  if (manifest_location_ == ManifestLocation::INSTALLED) {
+    // recovery tep value for installed package
+    std::string old_tep =
+        QueryTepPath(context_->pkgid.get(), context_->uid.get());
+    if (!old_tep.empty())
+      manifest->tep_name = strdup(old_tep.c_str());
+  }
 
   // write pkgid for recovery file
   if (context_->recovery_info.get().recovery_file) {
index 9b24ca3..16aaa2a 100644 (file)
@@ -47,7 +47,6 @@ Step::Status StepCopyTep::process() {
 
   bf::path tep_path =
       context_->pkg_path.get() / "res" / context_->tep_path.get().filename();
-  bs::error_code error;
 
   if (context_->is_tep_move.get()) {
     if (!MoveFile(context_->tep_path.get(), tep_path)) {
@@ -62,6 +61,8 @@ Step::Status StepCopyTep::process() {
     }
   }
   context_->tep_path.set(tep_path);
+  context_->manifest_data.get()->tep_name =
+      strdup(context_->tep_path.get().c_str());
 
   return Step::Status::OK;
 }
index 33efb93..c759b71 100644 (file)
@@ -5,17 +5,13 @@
 #include "common/step/pkgmgr/step_update_tep.h"
 
 #include <pkgmgr-info.h>
-#include <sys/types.h>
-#include <unistd.h>
 
 #include <boost/filesystem.hpp>
-#include <vcore/Certificate.h>
 
-#include <cassert>
-#include <cstdio>
 #include <cstring>
 #include <string>
 
+#include "common/backup_paths.h"
 #include "common/pkgmgr_registration.h"
 #include "common/utils/file_util.h"
 
@@ -25,22 +21,40 @@ namespace common_installer {
 namespace pkgmgr {
 
 Step::Status StepUpdateTep::process() {
-  if (context_->tep_path.get().empty())
-    return Status::OK;
-
-  if (!UpdateTepInfoInPkgmgr(context_->tep_path.get(),
-                          context_->pkgid.get(),
-                          context_->uid.get(),
-                          context_->request_mode.get())) {
-    LOG(ERROR) << "Cannot update tep info for application";
-    return Status::REGISTER_ERROR;
+  bf::path old_tep;
+  if (context_->old_manifest_data.get()->tep_name)
+    old_tep = context_->old_manifest_data.get()->tep_name;
+  if (!old_tep.empty() && context_->tep_path.get().empty()) {
+    // preserve old tep location during update if no new is given
+    context_->manifest_data.get()->tep_name = strdup(old_tep.c_str());
+
+    bf::path old_tep_location =
+        GetBackupPathForPackagePath(
+            context_->pkg_path.get()) / "res" / old_tep.filename();
+    bf::path new_tep_location = old_tep;
+    if (!MoveFile(old_tep_location, new_tep_location)) {
+      LOG(ERROR) << "Failed to copy tep file";
+      return Status::APP_DIR_ERROR;
+    }
   }
-
-  LOG(INFO) << "Successfully update the tep info for application";
   return Status::OK;
 }
 
 Step::Status StepUpdateTep::undo() {
+  bf::path old_tep;
+  if (context_->old_manifest_data.get()->tep_name)
+    old_tep = context_->old_manifest_data.get()->tep_name;
+  if (!old_tep.empty() && context_->tep_path.get().empty()) {
+    // restore old tep location during update rollback
+    bf::path old_tep_location =
+        GetBackupPathForPackagePath(
+            context_->pkg_path.get()) / "res" / old_tep.filename();
+    bf::path new_tep_location = old_tep;
+    if (!MoveFile(new_tep_location, old_tep_location)) {
+      LOG(ERROR) << "Failed to copy tep file";
+      return Status::APP_DIR_ERROR;
+    }
+  }
   return Status::OK;
 }
 
index 8daa61d..1f0c607 100644 (file)
@@ -10,6 +10,8 @@
 #include "common/installer_context.h"
 #include "common/step/step.h"
 
+#include <boost/filesystem/path.hpp>
+
 namespace common_installer {
 namespace pkgmgr {
 
@@ -20,7 +22,7 @@ class StepUpdateTep : public Step {
   Status process() override;
   Status clean() override { return Status::OK; }
   Status undo() override;
-  Status precheck() override { return Status::OK; };
+  Status precheck() override { return Status::OK; }
 
   SCOPE_LOG_TAG(UpdateTep)
 };