Rework handling PKGMGR_REQ_MANIFEST_DIRECT_INSTALL in StepConfigure 79/55079/6 accepted/tizen/mobile/20160108.064846 accepted/tizen/tv/20160108.064906 accepted/tizen/wearable/20160108.064934 submit/tizen/20160108.020058
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 21 Dec 2015 15:31:46 +0000 (16:31 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Thu, 7 Jan 2016 15:12:22 +0000 (16:12 +0100)
GetRequestInfo() will return pkgid in future and this will provide
all necessary information about ManifestDirectInstall and
ManifestDirectUpdate request type.

Change-Id: If4c58e0fc6c9520c6918c84b735c949fe7d82a97

src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
src/common/step/step_configure.cc

index 6e4d116..7e67520 100644 (file)
@@ -49,46 +49,12 @@ int PkgMgrInterface::InitInternal(int argc, char** argv) {
   }
 
   if (pkgmgr_installer_get_request_type(pi_)
-        == PKGMGR_REQ_MANIFEST_DIRECT_INSTALL) {
-    /* Add restrictions for manifest direct install
-      * - Directory should be located under /usr/apps/
-      * - XML path should be located under /usr/share/packages/
-      * - Directory name and xml name should be same */
-    bf::path directory_path = pkgmgr_installer_get_directory_path(pi_);
-    bf::path xml_path = pkgmgr_installer_get_xml_path(pi_);
-
-    if (directory_path.empty() ||
-        !bf::is_directory(directory_path) ||
-        xml_path.empty() ||
-        !bf::is_regular_file(xml_path)) {
-      LOG(ERROR) << "invalid parameter";
-      return EINVAL;
-    }
-
-    if (directory_path.parent_path().compare("/usr/apps") != 0) {
-      LOG(ERROR) << "invalid directory path";
-      return EINVAL;
-    }
-
-    if (xml_path.parent_path().compare("/usr/share/packages") != 0) {
-      LOG(ERROR) << "invalid xml path";
-      return EINVAL;
-    }
-
-    if (directory_path.filename().string()
-          .compare(xml_path.stem().string()) != 0) {
-      LOG(ERROR) << "invalid parameter: directory path "
-          << directory_path
-          << "xml path"
-          << xml_path;
-      return EINVAL;
-    }
-
+      == PKGMGR_REQ_MANIFEST_DIRECT_INSTALL) {
     // pkgid should be exists in preload app list
     std::ifstream preload_list("/etc/package-manager/preload/preload_list.txt");
     bool is_preload_app = false;
     for (std::string str; std::getline(preload_list, str); ) {
-      if (str.compare(directory_path.filename().string()) == 0) {
+      if (str == GetRequestInfo()) {
         is_preload_app = true;
         break;
       }
@@ -96,11 +62,11 @@ int PkgMgrInterface::InitInternal(int argc, char** argv) {
     preload_list.close();
 
     if (!is_preload_app) {
-      LOG(ERROR) << "Only preload app could be installed by manifest direct install";
+      LOG(ERROR) <<
+          "Only preload app could be installed by manifest direct install";
       return EINVAL;
     }
   }
-
   is_app_installed_ = false;
   if (query_interface_)
     is_app_installed_ = query_interface_->IsAppInstalledByArgv(argc, argv);
@@ -166,12 +132,4 @@ bool PkgMgrInterface::GetIsTepMove() {
   return (pkgmgr_installer_get_tep_move_type(pi_) == 1)?true:false;
 }
 
-boost::filesystem::path PkgMgrInterface::GetXMLPath() {
-  return boost::filesystem::path(pkgmgr_installer_get_xml_path(pi_));
-}
-
-boost::filesystem::path PkgMgrInterface::GetDirectoryPath() {
-  return boost::filesystem::path(pkgmgr_installer_get_directory_path(pi_));
-}
-
 }  // namespace common_installer
index 79f189f..5bbd935 100644 (file)
@@ -40,20 +40,6 @@ class PkgMgrInterface {
   const char *GetRequestInfo() const;
 
   /**
-   * Returns XML path passed from pkgmgr_installer
-   *
-   * \return XML info retrieved from pkgmgr_installer
-   */
-  boost::filesystem::path GetXMLPath();
-
-  /**
-   * Returns directory path passed from pkgmgr_installer
-   *
-   * \return Directory info retrieved from pkgmgr_installer
-   */
-  boost::filesystem::path GetDirectoryPath();
-
-  /**
    * Creates PkgMgrInterface
    *
    * \param argc main() argc argument passed to the backend
index 00f32ac..e0cd027 100644 (file)
@@ -4,6 +4,9 @@
 
 #include "common/step/step_configure.h"
 
+#include <boost/filesystem/path.hpp>
+
+#include <pkgmgr-info.h>
 #include <sys/stat.h>
 #include <tzplatform_config.h>
 #include <string>
 #include "common/request.h"
 #include "common/utils/file_util.h"
 
+namespace bf = boost::filesystem;
+
 namespace common_installer {
 namespace configuration {
 
-const char *kStrEmpty = "";
+const char kRpmPackageType[] = "rpm";
+const char kStrEmpty[] = "";
 
 StepConfigure::StepConfigure(InstallerContext* context, PkgMgrPtr pkgmgr)
     : Step(context),
@@ -64,19 +70,25 @@ Step::Status StepConfigure::process() {
       context_->pkgid.set(kStrEmpty);
       break;
     case RequestType::ManifestDirectInstall:
-    case RequestType::ManifestDirectUpdate:
+    case RequestType::ManifestDirectUpdate: {
       if (context_->request_mode.get() != RequestMode::GLOBAL) {
         LOG(ERROR) <<
           "Only global user allows to use Manifest Direct Install";
         return Status::CONFIG_ERROR;
       }
-      context_->xml_path.set(pkgmgr_->GetXMLPath());
-      context_->pkgid.set(context_->xml_path.get().stem().string());
-      context_->unpacked_dir_path.set(pkgmgr_->GetDirectoryPath());
-      context_->pkg_path.set(pkgmgr_->GetDirectoryPath());
+      context_->pkgid.set(pkgmgr_->GetRequestInfo());
+      bf::path package_directory =
+          context_->root_application_path.get() / context_->pkgid.get();
+      bf::path xml_path = bf::path(getUserManifestPath(context_->uid.get()))
+          / bf::path(context_->pkgid.get());
+      xml_path += ".xml";
+      context_->unpacked_dir_path.set(package_directory);
+      context_->pkg_path.set(package_directory);
+      context_->xml_path.set(xml_path);
       context_->privilege_level.set(common_installer::PrivilegeLevel::PUBLIC);
-      context_->pkg_type.set("rpm");  // temporary fix as rpm
+      context_->pkg_type.set(kRpmPackageType);  // temporary fix as rpm
       break;
+    }
     default:
       // TODO(p.sikorski): should return unsupported, and display error
       LOG(ERROR) <<