Change backup logic in mount update 19/286619/5
authorilho kim <ilho159.kim@samsung.com>
Mon, 2 Jan 2023 02:38:41 +0000 (11:38 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 11 Jan 2023 02:14:20 +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: I3eae62f8a27c4c85c2316ce78686a92dea1d822a
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/tpk/step/filesystem/step_tpk_prepare_package_directory.cc
src/tpk/step/filesystem/step_tpk_update_package_directory.cc [deleted file]
src/tpk/step/filesystem/step_tpk_update_package_directory.h [deleted file]
src/tpk/tpk_installer.cc

index 0241fbe70e1cecd5a516e4188302d13d4a3c5b41..5ee4033d656ddd4b6e39956a27b6ef9af059e57f 100644 (file)
@@ -21,10 +21,12 @@ namespace filesystem {
 
 ci::Step::Status StepTpkPreparePackageDirectory::BackupDirectory(
     const std::string& entry, const bf::path& backup_path) {
-  if (!bf::exists(context_->GetPkgPath() / entry))
+  std::string root_entry = entry.substr(0, entry.find("/"));
+  if (!bf::exists(context_->GetPkgPath() / root_entry))
     return Status::OK;
 
-  if (!ci::MoveDir(context_->GetPkgPath() / entry, backup_path / entry,
+  if (!ci::MoveDir(context_->GetPkgPath() / root_entry,
+      backup_path / root_entry,
       ci::FSFlag::FS_MERGE_OVERWRITE |
       ci::FSFlag::FS_COMMIT_COPY_FILE |
       ci::FSFlag::FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)) {
@@ -150,11 +152,12 @@ ci::Step::Status StepTpkPreparePackageDirectory::undo() {
     return Status::OK;
 
   for (auto& entry : tpk::GetExtractEntries()) {
-    ci::RemoveAll(context_->GetPkgPath() / entry);
-    if (!bf::exists(backupPath_ / entry))
+    std::string root_entry = entry.substr(0, entry.find("/"));
+    ci::RemoveAll(context_->GetPkgPath() / root_entry);
+    if (!bf::exists(backupPath_ / root_entry))
       continue;
 
-    ci::MoveDir(backupPath_ / entry, context_->GetPkgPath() / entry,
+    ci::MoveDir(backupPath_ / root_entry, context_->GetPkgPath() / root_entry,
         ci::FSFlag::FS_MERGE_OVERWRITE |
         ci::FSFlag::FS_COMMIT_COPY_FILE |
         ci::FSFlag::FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS);
diff --git a/src/tpk/step/filesystem/step_tpk_update_package_directory.cc b/src/tpk/step/filesystem/step_tpk_update_package_directory.cc
deleted file mode 100644 (file)
index ee0579f..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache-2.0 license that can be
-// found in the LICENSE file.
-
-#include "tpk/step/filesystem/step_tpk_update_package_directory.h"
-
-#include <boost/filesystem/operations.hpp>
-#include <boost/system/error_code.hpp>
-
-#include <common/utils/paths.h>
-#include <common/utils/file_util.h>
-
-#include <vector>
-
-#include "tpk/tpk_mount_path.h"
-
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
-namespace ci = common_installer;
-
-namespace {
-
-bool ReplacePaths(const bf::path& source, const bf::path& destination) {
-  if (!bf::exists(destination.parent_path())) {
-    if (!ci::CreateDir(destination.parent_path()))
-      return false;
-  }
-
-  if (!ci::MoveDir(source, destination)) {
-    LOG(ERROR) << "Failed to move " << source << " to " << destination;
-    return false;
-  }
-
-  return true;
-}
-
-}  // namespace
-
-namespace tpk {
-namespace filesystem {
-
-ci::Step::Status StepTpkUpdatePackageDirectory::BackupDirectory(
-    const std::string& entry, const boost::filesystem::path& backup_path) {
-  bf::path source = context_->GetPkgPath() / entry;
-
-  if (bf::exists(source)) {
-    bf::path destination = backup_path / entry;
-    if (!ReplacePaths(source, destination))
-      return Status::APP_DIR_ERROR;
-  }
-
-  return Status::OK;
-}
-
-ci::Step::Status StepTpkUpdatePackageDirectory::RestoreDirectory(
-    const std::string& entry, const boost::filesystem::path& backup_path) {
-  if (!bf::exists(backup_path / entry))
-    return Status::OK;
-
-  bf::path source = backup_path / entry;
-  bf::path destination = context_->GetPkgPath() / entry;
-  if (bf::exists(destination)) {
-    if (!ci::RemoveAll(destination))
-      return Status::APP_DIR_ERROR;
-  }
-
-  if (!ReplacePaths(source, destination))
-    return Status::APP_DIR_ERROR;
-
-  return Status::OK;
-}
-
-ci::Step::Status StepTpkUpdatePackageDirectory::RemoveDirectory(
-    const boost::filesystem::path& dir_path) {
-  if (!ci::RemoveAll(dir_path))
-    return Status::APP_DIR_ERROR;
-
-  return Status::OK;
-}
-
-ci::Step::Status StepTpkUpdatePackageDirectory::BackupEntries() {
-  bf::path backup_path =
-      ci::GetBackupPathForPackagePath(context_->GetPkgPath());
-
-  for (auto& entry : tpk::GetExtractEntries()) {
-    auto status = BackupDirectory(entry, backup_path);
-    if (status != Status::OK)
-      return status;
-  }
-
-  return Status::OK;
-}
-
-ci::Step::Status StepTpkUpdatePackageDirectory::process() {
-  auto status = BackupEntries();
-  if (status != Status::OK)
-    return status;
-
-  status = ExtractEntries();
-  if (status != Status::OK)
-    return status;
-
-  return PrepareLinks();
-}
-
-ci::Step::Status StepTpkUpdatePackageDirectory::clean() {
-  bf::path backup_path =
-      ci::GetBackupPathForPackagePath(context_->GetPkgPath());
-  RemoveDirectory(backup_path);
-
-  return Status::OK;
-}
-
-ci::Step::Status StepTpkUpdatePackageDirectory::undo() {
-  bf::path backup_path =
-      ci::GetBackupPathForPackagePath(context_->GetPkgPath());
-
-  for (auto& entry : tpk::GetExtractEntries()) {
-    auto status = RestoreDirectory(entry, backup_path);
-    if (status != Status::OK)
-      return status;
-  }
-
-  return RemoveDirectory(backup_path);
-}
-
-}  // namespace filesystem
-}  // namespace tpk
diff --git a/src/tpk/step/filesystem/step_tpk_update_package_directory.h b/src/tpk/step/filesystem/step_tpk_update_package_directory.h
deleted file mode 100644 (file)
index f647c00..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache-2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef TPK_STEP_FILESYSTEM_STEP_TPK_UPDATE_PACKAGE_DIRECTORY_H_
-#define TPK_STEP_FILESYSTEM_STEP_TPK_UPDATE_PACKAGE_DIRECTORY_H_
-
-#include <boost/filesystem/path.hpp>
-#include <manifest_parser/utils/logging.h>
-
-#include <string>
-
-#include "tpk/step/filesystem/step_tpk_prepare_package_directory.h"
-
-namespace tpk {
-namespace filesystem {
-
-/**
- * \brief Responsible for adjusting package directory after mounting zip package
- *        by StepMountUpdate
- *
- * This step will, additionally to base step actions, ,aintain backup
- * of directories from point 1) for operation rollback scenario.
- */
-class StepTpkUpdatePackageDirectory : public StepTpkPreparePackageDirectory {
- public:
-  using StepTpkPreparePackageDirectory::StepTpkPreparePackageDirectory;
-
-  Status process() override;
-  Status clean() override;
-  Status undo() override;
-
- private:
-  Status BackupEntries();
-  Status BackupDirectory(const std::string& entry,
-                          const boost::filesystem::path& backup_path);
-  Status RestoreDirectory(const std::string& entry,
-                          const boost::filesystem::path& backup_path);
-  Status RemoveDirectory(const boost::filesystem::path& dir_path);
-
-  STEP_NAME(TpkUpdatePackageDirectory)
-};
-
-}  // namespace filesystem
-}  // namespace tpk
-
-#endif  // TPK_STEP_FILESYSTEM_STEP_TPK_UPDATE_PACKAGE_DIRECTORY_H_
index b92dfa91f8f7aceb5188a32d8349dc19a99dcb9d..587caa77e09faad54a9c4c2ba7f125df3a9407b1 100644 (file)
@@ -15,7 +15,6 @@
 #include "tpk/step/filesystem/step_remove_external_storage_directories.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/filesystem/step_update_external_storage_directories.h"
 #include "tpk/step/pkgmgr/step_convert_xml.h"
 #include "tpk/step/pkgmgr/step_manifest_adjustment.h"