apply the concept of TPK insatllation as 'preload' 63/58863/3 accepted/tizen/mobile/20160205.064211 accepted/tizen/tv/20160205.064226 accepted/tizen/wearable/20160205.064246 submit/tizen/20160205.051501
authorjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 3 Feb 2016 12:23:01 +0000 (21:23 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Thu, 4 Feb 2016 09:58:37 +0000 (18:58 +0900)
And, modify the way of preload decision.

Requires:
https://review.tizen.org/gerrit/#/c/58866

Change-Id: I90a698a721ac58a132862eba7f6e960686b9d152
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/common/installer_context.cc
src/common/installer_context.h
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
src/common/request.cc
src/common/request.h
src/common/step/step_configure.cc
src/common/step/step_configure.h
src/common/step/step_delta_patch.cc
src/pkg_install_manifest/pkg_install_manifest.cc
src/pkgdir_tool/pkgdir_tool.cc

index 50554b8..340196b 100644 (file)
@@ -35,7 +35,8 @@ InstallerContext::InstallerContext()
       old_manifest_data(nullptr),
       uid(getuid()),
       backend_data(nullptr),
-      privilege_level(PrivilegeLevel::UNTRUSTED) {}
+      privilege_level(PrivilegeLevel::UNTRUSTED),
+      is_preload_request(false) {}
 
 InstallerContext::~InstallerContext() {
   if (manifest_data.get())
index 5bf43ba..521009c 100644 (file)
@@ -267,6 +267,11 @@ class InstallerContext {
    * \brief installation mode (ONLINE / OFFLINE)
    */
   Property<InstallationMode> installation_mode;
+
+  /**
+   * \brief preload request received from pkgmgr_installer
+   */
+  Property<bool> is_preload_request;
 };
 
 }  // namespace common_installer
index ea7a2bc..942acbb 100644 (file)
@@ -124,4 +124,10 @@ bool PkgMgrInterface::GetIsTepMove() {
   return (pkgmgr_installer_get_tep_move_type(pi_) == 1)?true:false;
 }
 
+bool PkgMgrInterface::GetIsPreloadRequest() {
+  return (pkgmgr_installer_get_is_preload(pi_) == 1)?
+      true:(install_mode_ == InstallationMode::OFFLINE)?
+      true:false;
+}
+
 }  // namespace common_installer
index d65c558..90d3891 100644 (file)
@@ -71,6 +71,13 @@ class PkgMgrInterface {
   bool GetIsTepMove();
 
   /**
+  * Returns True if the request is for preload. Otherwise, return false
+  *
+  * \return True if the request is for preload. Otherwise, return false
+  */
+  bool GetIsPreloadRequest();
+
+  /**
    * Get Raw pointer to pkgmgr_installer object
    * NOTE: It should not be used (PkgMgrInterface can destroy it
    *
index 6934077..1b4a022 100644 (file)
@@ -14,9 +14,10 @@ RequestMode GetRequestMode() {
       RequestMode::GLOBAL : RequestMode::USER;
 }
 
-const char *GetRootAppPath() {
+const char *GetRootAppPath(bool is_preload) {
   return GetRequestMode() == RequestMode::USER ?
-      tzplatform_getenv(TZ_USER_APP) : tzplatform_getenv(TZ_SYS_RW_APP);
+      tzplatform_getenv(TZ_USER_APP) : is_preload ?
+      tzplatform_getenv(TZ_SYS_RO_APP) :tzplatform_getenv(TZ_SYS_RW_APP);
 }
 
 }  // namespace common_installer
index a5df38e..20632cc 100644 (file)
@@ -39,7 +39,7 @@ RequestMode GetRequestMode();
  *
  * \return root application path (eg. $HOME/apps_rw/)
  */
-const char *GetRootAppPath();
+const char *GetRootAppPath(bool is_preload);
 
 }  // namespace common_installer
 
index 25f113f..d606328 100644 (file)
@@ -32,6 +32,7 @@ Step::Status StepConfigure::process() {
   SetupRequestMode();
   SetupRequestType();
   SetupFileCreationMask();
+  SetupIsPreloadRequest();
 
   if (!SetupRootAppDirectory())
     return Status::CONFIG_ERROR;
@@ -160,7 +161,8 @@ Step::Status StepConfigure::clean() {
 
 bool StepConfigure::SetupRootAppDirectory() {
   if (context_->root_application_path.get().empty()) {
-    std::string root_app_path = GetRootAppPath();
+    std::string root_app_path =
+        GetRootAppPath(context_->is_preload_request.get());
     if (root_app_path.empty())
       return false;
 
@@ -206,5 +208,9 @@ void StepConfigure::SetupFileCreationMask() {
       << " to " << std::oct <<  new_mask;
 }
 
+void StepConfigure::SetupIsPreloadRequest() {
+  context_->is_preload_request.set(pkgmgr_->GetIsPreloadRequest());
+}
+
 }  // namespace configuration
 }  // namespace common_installer
index 059924c..58e832c 100644 (file)
@@ -64,6 +64,7 @@ class StepConfigure : public Step {
   void SetupRequestMode();
   void SetupRequestType();
   void SetupFileCreationMask();
+  void SetupIsPreloadRequest();
 
   PkgMgrPtr pkgmgr_;
 
index a4c6e76..cf8a5a6 100644 (file)
@@ -80,10 +80,10 @@ bool ApplyDeletedFiles(const delta::DeltaInfo& info, const bf::path& app_dir) {
 }
 
 bool ApplyModifiedFiles(const delta::DeltaInfo& info, const bf::path& app_dir,
-                        const bf::path& patch_dir) {
+                        const bf::path& patch_dir, bool is_preload) {
   for (auto& relative : info.modified()) {
     bf::path temp_file = ci::GenerateTemporaryPath(
-        bf::path(ci::GetRootAppPath()) / "tmp_file");
+        bf::path(ci::GetRootAppPath(is_preload)) / "tmp_file");
     bf::path patch_file = patch_dir / relative;
     bf::path input = app_dir / relative;
     if (!bf::is_regular_file(input)) {
@@ -163,10 +163,10 @@ bool ApplyAddedFiles(const delta::DeltaInfo& info, const bf::path& app_dir,
 }
 
 bool ApplyPatch(const delta::DeltaInfo& info, const bf::path& app_dir,
-                const bf::path& patch_dir) {
+                const bf::path& patch_dir, bool is_preload) {
   if (!ApplyDeletedFiles(info, app_dir))
     return false;
-  if (!ApplyModifiedFiles(info, app_dir, patch_dir))
+  if (!ApplyModifiedFiles(info, app_dir, patch_dir, is_preload))
     return false;
   if (!ApplyAddedFiles(info, app_dir, patch_dir))
     return false;
@@ -245,7 +245,8 @@ Step::Status StepDeltaPatch::process() {
   }
 
   // apply changes mentioned in delta
-  if (!ApplyPatch(*delta_info, context_->unpacked_dir_path.get(), patch_dir_))
+  if (!ApplyPatch(*delta_info, context_->unpacked_dir_path.get(), patch_dir_,
+    context_->is_preload_request.get()))
     return Status::DELTA_ERROR;
 
   bs::error_code error;
index 57e4391..c14233f 100644 (file)
@@ -26,11 +26,15 @@ namespace {
 const char kBackendDirectoryPath[] = "/etc/package-manager/backend/";
 
 int InstallManifestOffline(const std::string& pkgid,
-                           const std::string& type) {
+                           const std::string& type,
+                           const std::string& preload) {
   bf::path backend_path(kBackendDirectoryPath);
   backend_path /= type;
   ci::Subprocess backend(backend_path.string());
-  backend.Run("-y", pkgid.c_str());
+  if (preload == "true")
+    backend.Run("-y", pkgid.c_str(), "--preload");
+  else
+    backend.Run("-y", pkgid.c_str());
   return backend.Wait();
 }
 
@@ -71,5 +75,6 @@ int main(int argc, char** argv) {
   if (type.empty())
     type = "tpk";
 
-  return InstallManifestOffline(package_info->package(), type);
+  return InstallManifestOffline(package_info->package(), type,
+      package_info->preload());
 }
index 23466e5..b335523 100644 (file)
@@ -36,15 +36,10 @@ namespace ci = common_installer;
 
 namespace {
 
-enum class Action {
-  CREATE,
-  COPY_OR_CREATE
-};
-
-const std::vector<std::pair<const char*, Action>> kEntries = {
-  {"/", Action::CREATE},
-  {"cache/", Action::CREATE},
-  {"data/", Action::COPY_OR_CREATE}  // compatibility -> copy data/ dir for tpk
+const std::vector<const char*> kEntries = {
+  {"/"},
+  {"cache/"},
+  {"data/"}
 };
 
 const char kSkelAppDir[] = "/etc/skel/apps_rw";
@@ -137,30 +132,12 @@ bool CreateDirectories(const bf::path& app_dir, const std::string& pkgid,
   }
 
   bs::error_code error;
-  for (auto& pair : kEntries) {
-    bf::path subpath = base_dir / pair.first;
-    switch (pair.second) {
-    case Action::COPY_OR_CREATE: {
-      bf::path global_directory =
-          bf::path(tzplatform_getenv(TZ_SYS_RW_APP)) / pkgid / pair.first;
-      if (bf::exists(global_directory)) {
-        if (!ci::CopyDir(global_directory, subpath)) {
-          LOG(ERROR) << "Failed to copy directory: " << global_directory;
-          return false;
-        }
-        break;
-      }
-    }
-    case Action::CREATE: {
-      bf::create_directories(subpath, error);
-      if (error) {
-        LOG(ERROR) << "Failed to create directory: " << subpath;
-        return false;
-      }
-      break;
-    }
-    default:
-      assert(false);
+  for (auto& entry : kEntries) {
+    bf::path subpath = base_dir / entry;
+    bf::create_directories(subpath, error);
+    if (error) {
+      LOG(ERROR) << "Failed to create directory: " << subpath;
+      return false;
     }
 
     if (!SetPackageDirectoryOwnerAndPermissions(subpath, uid, gid))
@@ -216,8 +193,8 @@ bool CreateSkelDirectories(const std::string& pkgid) {
   }
 
   // TODO(jungh.yeon) : this is hotfix.
-  for (auto& pair : kEntries) {
-    bf::path subpath = path / pair.first;
+  for (auto& entry : kEntries) {
+    bf::path subpath = path / entry;
     bf::create_directories(subpath, error);
     std::string label = "User::Pkg::" + pkgid;
     if (error) {