Replace pkg_path with GetPkgPath() method in InstallerContext 96/154196/11
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Mon, 9 Oct 2017 09:38:01 +0000 (11:38 +0200)
committerBartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Wed, 22 Nov 2017 09:10:45 +0000 (09:10 +0000)
pkg_path is always equal to root_application_path + pkgid.
Storing this information in separate variable is problematic,
because it requires to remember to update pkg_path after
root_application_path or pkgid is changed.

Submit with:
- https://review.tizen.org/gerrit/#/c/160353/
- https://review.tizen.org/gerrit/#/c/154904/

Change-Id: I8cc45cd003a642225be88669360b540186f8c678
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
31 files changed:
src/common/installer_context.h
src/common/step/backup/step_copy_backup.cc
src/common/step/configuration/step_configure.cc
src/common/step/configuration/step_parse_manifest.cc
src/common/step/filesystem/step_change_ownership_and_permission.cc
src/common/step/filesystem/step_copy.cc
src/common/step/filesystem/step_copy_storage_directories.cc
src/common/step/filesystem/step_copy_tep.cc
src/common/step/filesystem/step_create_storage_directories.cc
src/common/step/filesystem/step_create_storage_directories.h
src/common/step/filesystem/step_migrate_legacy_external_image.cc
src/common/step/filesystem/step_move_installed_storage.cc
src/common/step/filesystem/step_recover_change_owner.cc
src/common/step/filesystem/step_recover_external_storage.cc
src/common/step/filesystem/step_recover_files.cc
src/common/step/filesystem/step_recover_files.h
src/common/step/filesystem/step_recover_storage_directories.cc
src/common/step/filesystem/step_remove_files.cc
src/common/step/filesystem/step_remove_zip_image.cc
src/common/step/filesystem/step_update_storage_directories.cc
src/common/step/filesystem/step_update_tep.cc
src/common/step/mount/step_mount_install.cc
src/common/step/mount/step_mount_recover.cc
src/common/step/mount/step_mount_update.cc
src/common/step/pkgmgr/step_check_force_clean.cc
src/common/step/rds/step_rds_modify.cc
src/common/step/security/step_recover_security.cc
src/common/step/security/step_register_security.cc
src/common/step/security/step_register_trust_anchor.cc
src/common/step/security/step_rollback_deinstallation_security.cc
src/common/step/security/step_update_security.cc

index 07620dd..a45f01c 100644 (file)
@@ -180,6 +180,18 @@ class InstallerContext {
   ~InstallerContext();
 
   /**
+   * \brief Returns package directory path containing app data
+   */
+  inline boost::filesystem::path GetPkgPath() const {
+    return root_application_path.get() / pkgid.get();
+  }
+
+  /**
+   * \brief path to final location of installed package in filesystem
+   */
+  Property<std::string> pkgid;
+
+  /**
    * \brief package type (string representing name of backend)
    */
   Property<std::string> pkg_type;
@@ -218,16 +230,6 @@ class InstallerContext {
   Property<boost::filesystem::path> backup_xml_path;
 
   /**
-   * \brief path to final location of installed package in filesystem
-   */
-  Property<std::string> pkgid;
-
-  /**
-   * \brief package directory path containing app data
-   */
-  Property<boost::filesystem::path> pkg_path;
-
-  /**
    * \brief file path used for installation or reinstallation process
    */
   Property<boost::filesystem::path> file_path;
index 05805f7..4319f21 100644 (file)
@@ -39,11 +39,8 @@ Step::Status StepCopyBackup::precheck() {
     return Step::Status::INVALID_VALUE;
   }
 
-  // set package path
-  context_->pkg_path.set(
-      context_->root_application_path.get() / context_->pkgid.get());
-  install_path_ = context_->pkg_path.get();
-  backup_path_ = GetBackupPathForPackagePath(context_->pkg_path.get());
+  install_path_ = context_->GetPkgPath();
+  backup_path_ = GetBackupPathForPackagePath(context_->GetPkgPath());
 
   return Status::OK;
 }
@@ -103,7 +100,7 @@ bool StepCopyBackup::Backup() {
     }
   }
   // create copy of old package content skipping the external memory mount point
-  for (bf::directory_iterator iter(context_->pkg_path.get());
+  for (bf::directory_iterator iter(context_->GetPkgPath());
        iter != bf::directory_iterator(); ++iter) {
     if (iter->path().filename() == kExternalMemoryMountPoint)
       continue;
@@ -214,20 +211,20 @@ bool StepCopyBackup::CleanBackupDirectory() {
 
 bool StepCopyBackup::RollbackApplicationDirectory() {
   bs::error_code error;
-  if (bf::exists(context_->pkg_path.get())) {
-    bf::remove_all(context_->pkg_path.get(), error);
+  if (bf::exists(context_->GetPkgPath())) {
+    bf::remove_all(context_->GetPkgPath(), error);
     if (error) {
       return false;
     }
   }
 
-  if (!MoveDir(backup_path_, context_->pkg_path.get())) {
+  if (!MoveDir(backup_path_, context_->GetPkgPath())) {
     return false;
   }
 
   uid_t uid = context_->uid.get();
   // restore ownership changed during installation
-  if (!SetPackageDirectoryOwnerAndPermissions(context_->pkg_path.get(), uid))
+  if (!SetPackageDirectoryOwnerAndPermissions(context_->GetPkgPath(), uid))
     return false;
 
   return true;
index 11a338b..e0b675d 100644 (file)
@@ -49,7 +49,6 @@ Step::Status StepConfigure::process() {
     case RequestType::Install:
     case RequestType::Update:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
-      context_->pkgid.set(kStrEmpty);
       if (!pkgmgr_->GetTepPath().empty()) {
         context_->tep_path.set(pkgmgr_->GetTepPath());
         context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
@@ -73,7 +72,7 @@ Step::Status StepConfigure::process() {
       break;
     case RequestType::Delta:
       context_->unpacked_dir_path.set(kStrEmpty);
-      context_->pkgid.set(kStrEmpty);
+      context_->pkgid.set(pkgmgr_->GetRequestInfo());
       context_->file_path.set(pkgmgr_->GetRequestInfo());
       break;
     case RequestType::Move:
@@ -83,12 +82,10 @@ Step::Status StepConfigure::process() {
       break;
     case RequestType::Recovery:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
-      context_->pkgid.set(kStrEmpty);
       break;
     case RequestType::MountInstall:
     case RequestType::MountUpdate:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
-      context_->pkgid.set(kStrEmpty);
       if (!pkgmgr_->GetTepPath().empty()) {
         context_->tep_path.set(pkgmgr_->GetTepPath());
         context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
@@ -100,21 +97,18 @@ Step::Status StepConfigure::process() {
     case RequestType::ManifestDirectInstall:
     case RequestType::ManifestDirectUpdate: {
       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(),
               context_->is_readonly_package.get()))
           / bf::path(context_->pkgid.get());
       xml_path += ".xml";
-      context_->unpacked_dir_path.set(package_directory);
-      context_->pkg_path.set(package_directory);
+      context_->unpacked_dir_path.set(context_->GetPkgPath());
       context_->xml_path.set(xml_path);
       break;
     }
     case RequestType::ReadonlyUpdateInstall:
       context_->file_path.set(pkgmgr_->GetRequestInfo());
-      context_->pkgid.set(kStrEmpty);
+      context_->pkgid.set(pkgmgr_->GetRequestInfo());
       if (!pkgmgr_->GetTepPath().empty()) {
         context_->tep_path.set(pkgmgr_->GetTepPath());
         context_->is_tep_move.set(pkgmgr_->GetIsTepMove());
@@ -134,9 +128,6 @@ Step::Status StepConfigure::process() {
       break;
     case RequestType::MigrateExtImg: {
       context_->pkgid.set(pkgmgr_->GetRequestInfo());
-      bf::path package_directory =
-          context_->root_application_path.get() / context_->pkgid.get();
-      context_->pkg_path.set(package_directory);
       break;
     }
     default:
index 79b8ef9..8e1a1bd 100644 (file)
@@ -105,11 +105,9 @@ bool StepParseManifest::LocateConfigFile() {
   boost::filesystem::path manifest;
   switch (manifest_location_) {
     case ManifestLocation::RECOVERY: {
-      context_->pkg_path.set(
-          context_->root_application_path.get() / context_->pkgid.get());
       bf::path backup_path = common_installer::GetBackupPathForPackagePath(
-          context_->pkg_path.get()) / kManifestFileName;
-      bf::path in_package_path = context_->pkg_path.get() / kManifestFileName;
+          context_->GetPkgPath()) / kManifestFileName;
+      bf::path in_package_path = context_->GetPkgPath() / kManifestFileName;
       bf::path install_path =
           bf::path(getUserManifestPath(context_->uid.get(),
                       context_->is_readonly_package.get()))
@@ -390,7 +388,7 @@ bool StepParseManifest::FillPrivileges(manifest_x* manifest) {
       if (bf::path(priv.license).is_absolute())
         privilege->license = strdup(priv.license.c_str());
       else
-        privilege->license = strdup((context_->pkg_path.get()
+        privilege->license = strdup((context_->GetPkgPath()
             / priv.license).c_str());
     }
     manifest->appdefined_privileges =
@@ -426,7 +424,7 @@ bool StepParseManifest::FillProvidesAppDefinedPrivileges(
       if (bf::path(priv.license).is_absolute())
         privilege->license = strdup(priv.license.c_str());
       else
-        privilege->license = strdup((context_->pkg_path.get()
+        privilege->license = strdup((context_->GetPkgPath()
             / priv.license).c_str());
     }
     manifest->provides_appdefined_privileges =
@@ -945,7 +943,7 @@ void StepParseManifest::AppendSplashScreen(application_x* app,
   if (bf::path(src).is_absolute()) {
     splashscreen->src = strdup(src.c_str());
   } else {
-    bf::path full_path = context_->pkg_path.get() / src;
+    bf::path full_path = context_->GetPkgPath() / src;
     splashscreen->src = strdup(full_path.string().c_str());
   }
   if (src.substr(src.find_last_of(".") + 1) == "edj")
@@ -1166,8 +1164,6 @@ Step::Status StepParseManifest::process() {
           parser_->GetManifestData(app_keys::kManifestKey));
 
   context_->pkgid.set(info->package());
-  context_->pkg_path.set(
-      context_->root_application_path.get() / context_->pkgid.get());
 
   manifest_x* manifest =
       static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
index 19e2bf8..e9dab43 100644 (file)
@@ -195,14 +195,14 @@ Step::Status StepChangeOwnershipAndPermission::process() {
     return Status::ERROR;
 
   // Grant default permissions
-  if (!GrantDefaultPermissions(context_->pkg_path.get(), skip_symlink_))
+  if (!GrantDefaultPermissions(context_->GetPkgPath(), skip_symlink_))
     return Status::GRANT_PERMISSION_ERROR;
 
   // Change owner of files at root path
-  if (!ci::SetOwnershipAll(context_->pkg_path.get(), uid, *gid))
+  if (!ci::SetOwnershipAll(context_->GetPkgPath(), uid, *gid))
     return Status::ERROR;
 
-  if (!ChangeDataDir(context_->pkg_path.get(), uid))
+  if (!ChangeDataDir(context_->GetPkgPath(), uid))
     return Status::ERROR;
 
   // For icon files
index e3a921d..f86f746 100644 (file)
@@ -54,16 +54,12 @@ Step::Status StepCopy::precheck() {
 }
 
 Step::Status StepCopy::process() {
-  // set application path
-  context_->pkg_path.set(
-    context_->root_application_path.get() / context_->pkgid.get());
-
   bf::path install_path;
   if (context_->storage.get() == Storage::EXTENDED) {
     install_path = bf::path(GetExtendedRootAppPath(context_->uid.get())) /
         context_->pkgid.get();
   } else {
-    install_path = context_->pkg_path.get();
+    install_path = context_->GetPkgPath();
   }
 
   bs::error_code error;
@@ -84,7 +80,7 @@ Step::Status StepCopy::process() {
 
   if (context_->storage.get() == Storage::EXTENDED) {
     bs::error_code error;
-    bf::create_symlink(install_path, context_->pkg_path.get(), error);
+    bf::create_symlink(install_path, context_->GetPkgPath(), error);
     if (error) {
       LOG(ERROR) << "Failed to create symlink for extended path: "
                  << error.message();
@@ -109,7 +105,7 @@ Step::Status StepCopy::undo() {
     RemoveAll(install_path);
   }
 
-  if (!RemoveAll(context_->pkg_path.get()))
+  if (!RemoveAll(context_->GetPkgPath()))
     return Status::APP_DIR_ERROR;
   return Status::OK;
 }
index 104474c..3781d57 100644 (file)
@@ -41,7 +41,7 @@ bool StepCopyStorageDirectories::CopyAppStorage(
 
 common_installer::Step::Status StepCopyStorageDirectories::precheck() {
   backup_path_ =
-      common_installer::GetBackupPathForPackagePath(context_->pkg_path.get());
+      common_installer::GetBackupPathForPackagePath(context_->GetPkgPath());
 
   bs::error_code error_code;
   if (!bf::exists(backup_path_, error_code)) {
@@ -56,14 +56,14 @@ common_installer::Step::Status StepCopyStorageDirectories::process() {
   if (context_->request_mode.get() == RequestMode::GLOBAL)
     return Status::OK;
   if (!CopyAppStorage(backup_path_,
-                      context_->pkg_path.get(),
+                      context_->GetPkgPath(),
                       kDataLocation, true)) {
     LOG(ERROR) << "Failed to restore private directory for widget in update";
     return Status::APP_DIR_ERROR;
   }
 
   if (!CopyAppStorage(backup_path_,
-                      context_->pkg_path.get(),
+                      context_->GetPkgPath(),
                       kSharedResLocation, true)) {
     LOG(ERROR) << "Failed to restore shared directory for widget in update";
     return Status::APP_DIR_ERROR;
@@ -81,7 +81,7 @@ common_installer::Step::Status StepCopyStorageDirectories::undo() {
 
 bool StepCopyStorageDirectories::CacheDir() {
   bs::error_code error_code;
-  bf::path cache_path = context_->pkg_path.get() / kCache;
+  bf::path cache_path = context_->GetPkgPath() / kCache;
   bf::create_directory(cache_path, error_code);
   if (error_code) {
     LOG(ERROR) << "Failed to create cache directory for package";
index c357fd5..e6cce46 100644 (file)
@@ -42,16 +42,12 @@ Step::Status StepCopyTep::precheck() {
 Step::Status StepCopyTep::process() {
   if (context_->tep_path.get().empty())
     return Step::Status::OK;
-
-  context_->pkg_path.set(
-    context_->root_application_path.get() / context_->pkgid.get());
-
   bf::path tep_path;
   if (context_->external_storage) {
     tep_path = GetExternalTepPath(context_->request_mode.get(),
                                   context_->uid.get());
   } else {
-    tep_path = GetInternalTepPath(context_->pkg_path.get());
+    tep_path = GetInternalTepPath(context_->GetPkgPath());
   }
 
   // Keep filename of app store supplied file. Filename contains hash that
index e925010..b63e514 100644 (file)
@@ -39,7 +39,7 @@ namespace filesystem {
 common_installer::Step::Status StepCreateStorageDirectories::process() {
   if (context_->request_mode.get() == RequestMode::GLOBAL) {
     // remove packaged RW diriectories
-    if (!common_installer::DeleteStorageDirectories(context_->pkg_path.get())) {
+    if (!common_installer::DeleteStorageDirectories(context_->GetPkgPath())) {
       LOG(ERROR) << "Failed to remove storage directories";
       return Status::APP_DIR_ERROR;
     }
@@ -53,7 +53,7 @@ common_installer::Step::Status StepCreateStorageDirectories::process() {
       break;
     }
   }
-  if (!common_installer::CreateStorageDirectories(context_->pkg_path.get(),
+  if (!common_installer::CreateStorageDirectories(context_->GetPkgPath(),
                                                   manifest->api_version,
                                                   true, has_priv)) {
     LOG(ERROR) << "Failed to create storage directories";
index c2ce49d..a1f9b77 100644 (file)
@@ -21,7 +21,7 @@ namespace filesystem {
  * * Other methods are empty.
  *
  * CreateStorageDirectories works on below directories:
- * * context_->pkg_path.get(), eg:
+ * * context_->GetPkgPath(), eg:
  *   * TZ_SYS_RW/PKGID/<new-dir> (/usr/apps/PKGID/<new-dir>)
  *   * TZ_SER_APPS/PKGID/<new-dir>  (/{HOME}/apps_rw/PKGID/<new-dir>)
  */
index 6caa6d1..17970ff 100644 (file)
@@ -34,13 +34,13 @@ Step::Status StepMigrateLegacyExtImage::precheck() {
     return Step::Status::INVALID_VALUE;
   }
 
-  if (context_->pkg_path.get().empty()) {
+  if (context_->GetPkgPath().empty()) {
     LOG(ERROR) << "pkg_path attribute is empty";
     return Step::Status::INVALID_VALUE;
   }
-  if (!boost::filesystem::exists(context_->pkg_path.get())) {
+  if (!boost::filesystem::exists(context_->GetPkgPath())) {
     LOG(ERROR) << "pkg_path ("
-               << context_->pkg_path.get()
+               << context_->GetPkgPath()
                << ") path does not exist";
     return Step::Status::INVALID_VALUE;
   }
@@ -77,7 +77,7 @@ Step::Status StepMigrateLegacyExtImage::process() {
 
   std::string error_message;
   if (!RegisterSecurityContextForPathExternalOnly(pkgid,
-                        context_->pkg_type.get(), context_->pkg_path.get(),
+                        context_->pkg_type.get(), context_->GetPkgPath(),
                         uid, &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
index cd566c9..bf9a058 100644 (file)
@@ -91,7 +91,7 @@ void StepMoveInstalledStorage::SetTepPaths() {
                                        context_->uid.get());
     new_tep_location_ /= old_tep_location_.filename();
   } else {
-    new_tep_location_ = GetInternalTepPath(context_->pkg_path.get()) /
+    new_tep_location_ = GetInternalTepPath(context_->GetPkgPath()) /
         old_tep_location_.filename();
   }
 }
@@ -168,7 +168,7 @@ bool StepMoveInstalledStorage::MoveBackExternal() {
 
 bool StepMoveInstalledStorage::MoveExtended() {
   if (move_type_ == MoveType::TO_EXTENDED) {
-    old_pkg_location_ = context_->pkg_path.get();
+    old_pkg_location_ = context_->GetPkgPath();
     new_pkg_location_ = bf::path(GetExtendedRootAppPath(context_->uid.get())) /
         context_->pkgid.get();
     context_->storage.set(Storage::EXTENDED);
index 9784518..59a6c7d 100644 (file)
@@ -61,7 +61,7 @@ namespace filesystem {
 Step::Status StepRecoverChangeOwner::RecoveryUpdate() {
   uid_t uid = context_->uid.get();
   // Change owner of files at root path
-  if (!ci::SetPackageDirectoryOwnerAndPermissions(context_->pkg_path.get(),
+  if (!ci::SetPackageDirectoryOwnerAndPermissions(context_->GetPkgPath(),
       uid))
     return Step::Status::ERROR;
 
@@ -75,7 +75,7 @@ Step::Status StepRecoverChangeOwner::RecoveryUpdate() {
 Step::Status StepRecoverChangeOwner::RecoveryMountUpdate() {
   uid_t uid = context_->uid.get();
   // Change owner of files at root path
-  if (!ci::SetPackageDirectoryOwnerAndPermissions(context_->pkg_path.get(),
+  if (!ci::SetPackageDirectoryOwnerAndPermissions(context_->GetPkgPath(),
       uid))
     return Step::Status::ERROR;
 
@@ -84,10 +84,10 @@ Step::Status StepRecoverChangeOwner::RecoveryMountUpdate() {
     return Step::Status::ERROR;
 
   // Change owner of files at root path
-  if (!ci::SetOwnershipAll(context_->pkg_path.get(), uid, *gid))
+  if (!ci::SetOwnershipAll(context_->GetPkgPath(), uid, *gid))
     return Status::ERROR;
 
-  if (!ChangeDataDir(context_->pkg_path.get(), uid))
+  if (!ChangeDataDir(context_->GetPkgPath(), uid))
     return Status::ERROR;
 
   return ChangeOwnershipIconsAndManifest(gid, uid);
index 46c7c0a..9941983 100644 (file)
@@ -18,7 +18,7 @@ namespace filesystem {
 
 Step::Status StepRecoverExternalStorage::process() {
   if (!context_->manifest_data.get()) {
-    RemoveAll(context_->pkg_path.get());
+    RemoveAll(context_->GetPkgPath());
   } else {
     (void) StepAcquireExternalStorage::process();
   }
index 4da4b2b..4a36e8b 100644 (file)
@@ -18,11 +18,7 @@ namespace common_installer {
 namespace filesystem {
 
 Step::Status StepRecoverFiles::RecoveryNew() {
-  if (!SetPackagePath()) {
-    LOG(DEBUG) << "Package files recovery not needed";
-    return Status::OK;
-  }
-  if (!RemoveAll(context_->pkg_path.get()))
+  if (!RemoveAll(context_->GetPkgPath()))
     return Status::RECOVERY_ERROR;
 
   LOG(INFO) << "Package files recovery done";
@@ -30,42 +26,30 @@ Step::Status StepRecoverFiles::RecoveryNew() {
 }
 
 Step::Status StepRecoverFiles::RecoveryUpdate() {
-  if (!SetPackagePath()) {
-    LOG(DEBUG) << "Package files recovery not needed";
-    return Status::OK;
-  }
-  bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
+  bf::path backup_path = GetBackupPathForPackagePath(context_->GetPkgPath());
   if (bf::exists(backup_path)) {
-    if (!RemoveAll(context_->pkg_path.get())) {
+    if (!RemoveAll(context_->GetPkgPath())) {
       LOG(ERROR) << "Cannot restore widget files to its correct location";
       return Status::RECOVERY_ERROR;
     }
-    (void) MoveDir(backup_path, context_->pkg_path.get());
+    (void) MoveDir(backup_path, context_->GetPkgPath());
   }
   LOG(INFO) << "Package files recovery done";
   return Status::OK;
 }
 
 Step::Status StepRecoverFiles::RecoveryMountNew() {
-  if (!SetPackagePath()) {
-    LOG(DEBUG) << "Package files recovery not needed";
-    return Status::OK;
-  }
   bf::path zip_location = GetZipPackageLocation(
-        context_->pkg_path.get(), context_->pkgid.get());
+        context_->GetPkgPath(), context_->pkgid.get());
   Remove(zip_location);
-  RemoveAll(context_->pkg_path.get());
+  RemoveAll(context_->GetPkgPath());
   LOG(INFO) << "Package files recovery done";
   return Status::OK;
 }
 
 Step::Status StepRecoverFiles::RecoveryMountUpdate() {
-  if (!SetPackagePath()) {
-    LOG(DEBUG) << "Package files recovery not needed";
-    return Status::OK;
-  }
   bf::path zip_location = GetZipPackageLocation(
-        context_->pkg_path.get(), context_->pkgid.get());
+        context_->GetPkgPath(), context_->pkgid.get());
   bf::path backup_zip_location = GetBackupPathForZipFile(zip_location);
   if (bf::exists(backup_zip_location)) {
     Remove(zip_location);
@@ -77,9 +61,9 @@ Step::Status StepRecoverFiles::RecoveryMountUpdate() {
   // directories without mounting zip package file. In other words in mount
   // install or mount update mode we don't mount everything - some files are
   // still unpacked due to necessity.
-  bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
+  bf::path backup_path = GetBackupPathForPackagePath(context_->GetPkgPath());
   if (bf::exists(backup_path)) {
-    if (!MoveDir(backup_path, context_->pkg_path.get(),
+    if (!MoveDir(backup_path, context_->GetPkgPath(),
                  FS_MERGE_OVERWRITE | FS_COMMIT_COPY_FILE)) {
       LOG(ERROR) << "Failed to recovery backup file "
                  << "in recovery of mount update";
@@ -91,14 +75,6 @@ Step::Status StepRecoverFiles::RecoveryMountUpdate() {
   return Status::OK;
 }
 
-bool StepRecoverFiles::SetPackagePath() {
-  if (context_->pkgid.get().empty())
-    return false;
-  context_->pkg_path.set(
-      context_->root_application_path.get() / context_->pkgid.get());
-  return true;
-}
-
 }  // namespace filesystem
 }  // namespace common_installer
 
index 603757f..7895290 100644 (file)
@@ -30,9 +30,6 @@ class StepRecoverFiles : public recovery::StepRecovery {
   Status RecoveryMountNew() override;
   Status RecoveryMountUpdate() override;
 
- private:
-  bool SetPackagePath();
-
   STEP_NAME(RecoverFiles)
 };
 
index 087d1b2..082411a 100644 (file)
@@ -36,12 +36,12 @@ bool StepRecoverStorageDirectories::MoveAppStorage(
 Step::Status StepRecoverStorageDirectories::RecoveryUpdate() {
   if (context_->request_mode.get() == RequestMode::GLOBAL)
     return Status::OK;
-  if (!context_->pkg_path.get().empty()) {
+  if (!context_->GetPkgPath().empty()) {
     bf::path backup_path = common_installer::GetBackupPathForPackagePath(
-        context_->pkg_path.get());
+        context_->GetPkgPath());
     if (bf::exists(backup_path)) {
-      MoveAppStorage(context_->pkg_path.get(), backup_path, kDataLocation);
-      MoveAppStorage(context_->pkg_path.get(), backup_path, kSharedResLocation);
+      MoveAppStorage(context_->GetPkgPath(), backup_path, kDataLocation);
+      MoveAppStorage(context_->GetPkgPath(), backup_path, kSharedResLocation);
     }
   }
   return Status::OK;
index a49e6ad..807a6fd 100644 (file)
@@ -50,11 +50,11 @@ Step::Status StepRemoveFiles::precheck() {
 
   // Even though, the below checks can fail, StepRemoveFiles should still try
   // to remove the files
-  if (context_->pkg_path.get().empty())
+  if (context_->GetPkgPath().empty())
     LOG(ERROR) << "pkg_path attribute is empty";
-  else if (!bf::exists(context_->pkg_path.get()))
+  else if (!bf::exists(context_->GetPkgPath()))
     LOG(ERROR) << "pkg_path ("
-               << context_->pkg_path.get()
+               << context_->GetPkgPath()
                << ") path does not exist";
 
   return Step::Status::OK;
index 7a7a5aa..c09330a 100644 (file)
@@ -30,7 +30,7 @@ Step::Status StepRemoveZipImage::precheck() {
 
 Step::Status StepRemoveZipImage::process() {
   bf::path zip_image_path =
-      GetZipPackageLocation(context_->pkg_path.get(), context_->pkgid.get());
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
   if (bf::exists(zip_image_path)) {
     if (Remove(zip_image_path))
       LOG(INFO) << "Zip image file removed: " << zip_image_path;
index 292cb7b..8fe5860 100644 (file)
@@ -51,7 +51,7 @@ Step::Status StepUpdateStorageDirectories::process() {
   std::string str_ver(manifest->api_version);
   utils::VersionNumber api_version(str_ver);
 
-  bf::path shared_data_path = context_->pkg_path.get() / kSharedData;
+  bf::path shared_data_path = context_->GetPkgPath() / kSharedData;
   if (api_version < ver30) {
     return CreateSharedDir(shared_data_path);
   } else {
index 91ace28..d81e870 100644 (file)
@@ -53,7 +53,7 @@ Step::Status StepUpdateTep::process() {
       bf::path new_path = context_->manifest_data.get()->tep_name;
       bf::path backup_path =
           GetInternalTepPath(
-              GetBackupPathForPackagePath(context_->pkg_path.get()));
+              GetBackupPathForPackagePath(context_->GetPkgPath()));
       backup_path /= new_path.filename();
       if (!bf::exists(new_path.parent_path())) {
         bs::error_code error;
index b6467a9..0714136 100644 (file)
@@ -21,9 +21,6 @@ namespace common_installer {
 namespace mount {
 
 Step::Status StepMountInstall::process() {
-  context_->pkg_path.set(
-      context_->root_application_path.get() / context_->pkgid.get());
-
   TzipInterface tzip_unpack(context_->unpacked_dir_path.get());
   if (!tzip_unpack.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package from temporary path";
@@ -31,7 +28,7 @@ Step::Status StepMountInstall::process() {
   }
 
   bf::path zip_destination_path =
-      GetZipPackageLocation(context_->pkg_path.get(), context_->pkgid.get());
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
   if (!bf::exists(zip_destination_path.parent_path())) {
     bs::error_code error;
     bf::create_directories(zip_destination_path.parent_path(), error);
@@ -48,7 +45,7 @@ Step::Status StepMountInstall::process() {
   context_->manifest_data.get()->zip_mount_file =
       strdup(zip_destination_path.c_str());
 
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
@@ -60,7 +57,7 @@ Step::Status StepMountInstall::process() {
 }
 
 Step::Status StepMountInstall::UmountPackagePath() {
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
@@ -77,13 +74,13 @@ Step::Status StepMountInstall::clean() {
 Step::Status StepMountInstall::undo() {
   bs::error_code error;
   UmountPackagePath();
-  bf::remove(GetZipPackageLocation(context_->pkg_path.get(),
+  bf::remove(GetZipPackageLocation(context_->GetPkgPath(),
                                    context_->pkgid.get()), error);
   if (error) {
     LOG(ERROR) << "Failed to remove zip package";
     return Status::APP_DIR_ERROR;
   }
-  bf::remove_all(context_->pkg_path.get(), error);
+  bf::remove_all(context_->GetPkgPath(), error);
   if (error) {
     LOG(ERROR) << "Failed to remove package content";
     return Status::APP_DIR_ERROR;
index 4012357..445942c 100644 (file)
@@ -17,11 +17,11 @@ namespace mount {
 
 Step::Status StepMountRecover::RecoveryMountUpdate() {
   bf::path zip_destination_path =
-      GetZipPackageLocation(context_->pkg_path.get(), context_->pkgid.get());
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
   context_->manifest_data.get()->zip_mount_file =
       strdup(zip_destination_path.c_str());
 
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
@@ -42,7 +42,7 @@ Step::Status StepMountRecover::undo() {
 }
 
 Step::Status StepMountRecover::UmountPackagePath() {
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
index 1915f3f..bca5093 100644 (file)
@@ -21,9 +21,6 @@ namespace common_installer {
 namespace mount {
 
 Step::Status StepMountUpdate::process() {
-  context_->pkg_path.set(
-     context_->root_application_path.get() / context_->pkgid.get());
-
   TzipInterface tzip_unpack(context_->unpacked_dir_path.get());
   if (!tzip_unpack.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package from temporary path";
@@ -31,7 +28,7 @@ Step::Status StepMountUpdate::process() {
   }
 
   bf::path zip_destination_path =
-      GetZipPackageLocation(context_->pkg_path.get(), context_->pkgid.get());
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
   bf::path backup_zip_location = GetBackupPathForZipFile(zip_destination_path);
 
   if (!MoveFile(zip_destination_path, backup_zip_location)) {
@@ -45,7 +42,7 @@ Step::Status StepMountUpdate::process() {
   context_->manifest_data.get()->zip_mount_file =
       strdup(zip_destination_path.c_str());
 
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
@@ -59,11 +56,11 @@ Step::Status StepMountUpdate::process() {
 Step::Status StepMountUpdate::clean() {
   bf::path backup_zip_location =
       GetBackupPathForZipFile(GetZipPackageLocation(
-          context_->pkg_path.get(), context_->pkgid.get()));
+          context_->GetPkgPath(), context_->pkgid.get()));
   bs::error_code error;
   bf::remove(backup_zip_location, error);
 
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
@@ -73,7 +70,7 @@ Step::Status StepMountUpdate::clean() {
 }
 
 Step::Status StepMountUpdate::undo() {
-  bf::path mount_point = GetMountLocation(context_->pkg_path.get());
+  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
   TzipInterface tzip_final(mount_point);
   if (!tzip_final.UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
@@ -81,7 +78,7 @@ Step::Status StepMountUpdate::undo() {
   }
 
   bf::path zip_location = GetZipPackageLocation(
-        context_->pkg_path.get(), context_->pkgid.get());
+        context_->GetPkgPath(), context_->pkgid.get());
   bf::path backup_zip_location = GetBackupPathForZipFile(zip_location);
 
   if (bf::exists(backup_zip_location)) {
index 90be356..5490324 100644 (file)
@@ -40,7 +40,6 @@ Step::Status StepCheckForceClean::process() {
     if (!PkgmgrGenerateManifestInfoFromDB(manifest, context_->pkgid.get(),
             context_->uid.get())) {
       context_->manifest_data.set(manifest);
-      context_->pkg_path.set(manifest->root_path);
     }
   }
 
index f6d12a7..2b4b60c 100644 (file)
@@ -31,6 +31,10 @@ Step::Status StepRDSModify::precheck() {
                << ") path does not exist";
     return Step::Status::INVALID_VALUE;
   }
+  if (context_->root_application_path.get().empty()) {
+    LOG(ERROR) << "pkgid is not set";
+    return Step::Status::PACKAGE_NOT_FOUND;
+  }
   if (context_->pkgid.get().empty()) {
     LOG(ERROR) << "pkgid is not set";
     return Step::Status::PACKAGE_NOT_FOUND;
@@ -48,9 +52,7 @@ Step::Status StepRDSModify::process() {
     LOG(ERROR) << "unable to setup temp directory";
     return Step::Status::ERROR;
   }
-  context_->pkg_path.set(
-        context_->root_application_path.get() /context_->pkgid.get());
-  bf::path install_path = context_->pkg_path.get();
+  bf::path install_path = context_->GetPkgPath();
   bf::path unzip_path = context_->unpacked_dir_path.get();
   if (!AddFiles(unzip_path, install_path) ||
      !ModifyFiles(unzip_path, install_path) ||
@@ -154,7 +156,7 @@ bool StepRDSModify::PerformBackup(std::string relative_path,
   if (backup_temp_dir_.empty())
     return false;
   if (operation == Operation::DELETE || operation == Operation::MODIFY) {
-    bf::path app_path = context_->pkg_path.get();
+    bf::path app_path = context_->GetPkgPath();
     bf::path source_path = app_path  / relative_path;
     if (bf::is_directory(source_path)) {
       if (!CreateDir(backup_temp_dir_ / relative_path)) {
@@ -183,7 +185,7 @@ bool StepRDSModify::PerformBackup(std::string relative_path,
 
 void StepRDSModify::RestoreFiles() {
   LOG(ERROR) << "error occured about to restore files";
-  bf::path app_path(context_->pkg_path.get());
+  bf::path app_path(context_->GetPkgPath());
   for (std::pair<std::string, Operation>& modification :
        success_modifications_) {
     bf::path source_path(backup_temp_dir_ / modification.first);
index 1a2ff5f..60114ce 100644 (file)
@@ -13,9 +13,9 @@ namespace common_installer {
 namespace security {
 
 bool StepRecoverSecurity::Check(bool is_update) {
-  if (context_->pkg_path.get().empty())
+  if (context_->GetPkgPath().empty())
     return false;
-  if (!boost::filesystem::exists(context_->pkg_path.get()) && is_update)
+  if (!boost::filesystem::exists(context_->GetPkgPath()) && is_update)
     return false;
   if (context_->pkgid.get().empty())
     return false;
@@ -56,7 +56,7 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
   }
   std::string error_message;
   if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       &context_->certificate_info.get(), context_->manifest_data.get(),
       context_->cross_app_rules.get(), &error_message)) {
     LOG(ERROR) << "Unsuccessful update";
@@ -67,7 +67,7 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     return Status::RECOVERY_ERROR;
   }
   if (!RegisterSecurityContextForPath(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
index 875da58..83cd55b 100644 (file)
@@ -13,13 +13,13 @@ namespace common_installer {
 namespace security {
 
 Step::Status StepRegisterSecurity::precheck() {
-  if (context_->pkg_path.get().empty()) {
+  if (context_->GetPkgPath().empty()) {
     LOG(ERROR) << "pkg_path attribute is empty";
     return Step::Status::INVALID_VALUE;
   }
-  if (!boost::filesystem::exists(context_->pkg_path.get())) {
+  if (!boost::filesystem::exists(context_->GetPkgPath())) {
     LOG(ERROR) << "pkg_path ("
-               << context_->pkg_path.get()
+               << context_->GetPkgPath()
                << ") path does not exist";
     return Step::Status::INVALID_VALUE;
   }
@@ -41,7 +41,7 @@ Step::Status StepRegisterSecurity::process() {
   std::string error_message;
   if (context_->request_type.get() != RequestType::Move &&
       !RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       &context_->certificate_info.get(), context_->manifest_data.get(),
       context_->cross_app_rules.get(), &error_message)) {
     if (!error_message.empty()) {
@@ -53,7 +53,7 @@ Step::Status StepRegisterSecurity::process() {
   if (context_->partial_rw.get())
     return Status::OK;
   if (!RegisterSecurityContextForPath(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
index 0a15d97..7b2f941 100644 (file)
@@ -52,7 +52,7 @@ Step::Status StepRegisterTrustAnchor::precheck() {
 
 Step::Status StepRegisterTrustAnchor::process() {
   int ret;
-  bf::path pkg_certs_path = context_->pkg_path.get() / kTpkTrustAnchorPath;
+  bf::path pkg_certs_path = context_->GetPkgPath() / kTpkTrustAnchorPath;
   if (register_type_ == RegisterType::UPDATE) {
     ret = trust_anchor_uninstall(context_->pkgid.get().c_str(),
         context_->uid.get());
@@ -79,7 +79,7 @@ Step::Status StepRegisterTrustAnchor::process() {
     if (!common_installer::CreateDir(pkg_certs_path))
       return Step::Status::APP_DIR_ERROR;
     bf::path pkg_certs_src_path =
-        context_->pkg_path.get() / "res/wgt" / kWgtTrustAnchorPath;
+        context_->GetPkgPath() / "res/wgt" / kWgtTrustAnchorPath;
     for (bf::directory_iterator file(pkg_certs_src_path);
         file != bf::directory_iterator(); ++file) {
       bf::path current(file->path());
index 8e2f21f..fbe4487 100644 (file)
@@ -28,7 +28,7 @@ Step::Status StepRollbackDeinstallationSecurity::precheck() {
 Step::Status StepRollbackDeinstallationSecurity::undo() {
   std::string error_message;
   if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       &context_->certificate_info.get(), context_->manifest_data.get(),
       context_->cross_app_rules.get(), &error_message)) {
     LOG(ERROR) << "Failure on re-installing security context for app "
@@ -39,7 +39,7 @@ Step::Status StepRollbackDeinstallationSecurity::undo() {
     return Status::SECURITY_ERROR;
   }
   if (!RegisterSecurityContextForPath(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
index bc6c3bb..b796985 100644 (file)
@@ -14,7 +14,7 @@ namespace security {
 Step::Status StepUpdateSecurity::process() {
   std::string error_message;
   if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       &context_->certificate_info.get(), context_->manifest_data.get(),
       context_->cross_app_rules.get(), &error_message)) {
     if (!error_message.empty()) {
@@ -25,7 +25,7 @@ Step::Status StepUpdateSecurity::process() {
   }
   if (context_->request_type.get() != RequestType::ReadonlyUpdateUninstall) {
     if (!RegisterSecurityContextForPath(
-        context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+        context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
         context_->is_readonly_package.get(), &error_message)) {
       if (!error_message.empty()) {
         LOG(ERROR) << "error_message: " << error_message;
@@ -41,7 +41,7 @@ Step::Status StepUpdateSecurity::process() {
 Step::Status StepUpdateSecurity::undo() {
   std::string error_message;
   if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       &context_->certificate_info.get(), context_->old_manifest_data.get(),
       context_->cross_app_rules.get(), &error_message)) {
     if (!error_message.empty()) {
@@ -50,7 +50,7 @@ Step::Status StepUpdateSecurity::undo() {
     return Status::SECURITY_ERROR;
   }
   if (!RegisterSecurityContextForPath(
-      context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;