Change backup logic in mount update 21/286621/3
authorilho kim <ilho159.kim@samsung.com>
Tue, 10 Jan 2023 12:18:07 +0000 (21:18 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 11 Jan 2023 02:14:36 +0000 (11:14 +0900)
If the file to be backed up is a hierarchical structure, the move
operation is failed and the copy operation is executed
As a result, the ownership and permission and smack label disappears
in this case, Move the top directory to preserve it

Change-Id: Ife987fd4bd617a623df6dd553e797a8fb57d5530
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/hybrid/hybrid_installer.cc
src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc
src/wgt/step/filesystem/step_wgt_update_package_directory.cc

index df7495b..d96fa36 100644 (file)
@@ -15,7 +15,6 @@
 #include <tpk/step/filesystem/step_create_tpk_symbolic_link.h>
 #include <tpk/step/filesystem/step_tpk_patch_icons.h>
 #include <tpk/step/filesystem/step_tpk_prepare_package_directory.h>
-#include <tpk/step/filesystem/step_tpk_update_package_directory.h>
 #include <tpk/step/pkgmgr/step_manifest_adjustment.h>
 #include <tpk/step/security/step_tpk_recover_signature.h>
 
@@ -230,7 +229,7 @@ void HybridInstaller::MountUpdateSteps() {
       "CheckWgtNotificationCategory");
   AddStepAfter<hybrid::encryption::StepEncryptHybridResources>(
       "CheckWgtImePrivilege");
-  AddStepAfter<tpk::filesystem::StepTpkUpdatePackageDirectory>("MountUpdate");
+  AddStepAfter<tpk::filesystem::StepTpkPreparePackageDirectory>("MountUpdate");
   AddStepAfter<tpk::filesystem::StepTpkPatchIcons>("CreateIcons");
   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("TpkPatchIcons", true);
   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
index 2439ded..7559f45 100644 (file)
@@ -88,13 +88,7 @@ ci::Step::Status StepWgtPreparePackageDirectory::ExtractEntries() {
   }
 
   for (auto& entry : GetExtractEntries()) {
-    if (context_->request_type.get() == ci::RequestType::MountInstall) {
-      ci::RemoveAll(resource_path / entry);
-    } else if (context_->request_type.get() == ci::RequestType::MountUpdate) {
-      if (!ci::BackupDir(resource_path, backup_path, entry))
-        return Status::APP_DIR_ERROR;
-    }
-
+    ci::RemoveAll(resource_path / entry);
     if (!ci::ExtractToTmpDir(context_->file_path.get().c_str(),
             resource_path.c_str(), entry)) {
       LOG(ERROR) << "Failed to extract file";
index 9cb801d..b23378e 100644 (file)
 #include <common/utils/paths.h>
 #include <common/utils/file_util.h>
 
+#include <string>
+#include <vector>
+
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
 namespace ci = common_installer;
 
 namespace {
 
-const char* kBackupEntries[] = {
+
+const std::vector<std::string> kBackupEntries = {
   "bin",
-  "shared/res"
+  "shared/res",
+  "res/wgt"
 };
 
 bool MoveCreateDir(const bf::path& source, const bf::path& destination) {
-  if (!bf::exists(destination.parent_path())) {
-    bs::error_code error;
-    bf::create_directories(destination.parent_path(), error);
-    if (error) {
-      LOG(ERROR) << "Cannot create directory: " << destination.parent_path();
-      return false;
-    }
-  }
   if (!ci::MoveDir(source, destination)) {
     LOG(ERROR) << "Failed to move directory " << destination;
     return false;
@@ -48,11 +45,12 @@ StepWgtUpdatePackageDirectory::CreateBackupOfDirectories() {
   bf::path backup_path =
       ci::GetBackupPathForPackagePath(context_->GetPkgPath());
   for (auto& entry : kBackupEntries) {
-    bf::path directory = context_->GetPkgPath() / entry;
+    std::string root_entry = entry.substr(0, entry.find("/"));
+    bf::path directory = context_->GetPkgPath() / root_entry;
     if (!bf::exists(directory))
       continue;
     LOG(DEBUG) << "Backup directory entry: " << entry;
-    bf::path directory_backup = backup_path / entry;
+    bf::path directory_backup = backup_path / root_entry;
     if (!MoveCreateDir(directory, directory_backup)) {
       LOG(ERROR) << "Failed to create backup directory "
                  << directory_backup;
@@ -72,8 +70,9 @@ StepWgtUpdatePackageDirectory::RecoverBackupOfDirectories() {
     return Status::OK;
 
   for (auto& entry : kBackupEntries) {
-    bf::path directory = context_->GetPkgPath() / entry;
-    bf::path directory_backup = backup_path / entry;
+    std::string root_entry = entry.substr(0, entry.find("/"));
+    bf::path directory = context_->GetPkgPath() / root_entry;
+    bf::path directory_backup = backup_path / root_entry;
     if (!bf::exists(directory_backup))
         continue;
     LOG(DEBUG) << "Recover directory entry: " << entry;