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)) {
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);
+++ /dev/null
-// 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
+++ /dev/null
-// 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_