From: Junghyun Yeon Date: Wed, 26 Jul 2017 11:58:24 +0000 (+0900) Subject: Change StepTpkPreparePackageDirectory X-Git-Tag: accepted/tizen/4.0/unified/20170816.012316~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d253c96d133caa6c0846738e6fb3aa51b7e41772;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Change StepTpkPreparePackageDirectory - make backup directory and store existing data to preserve previous data. - backup directory will be removed whether request has succeed or not. But it will be used if request has failed. Change-Id: I3a2a89add859d05e89f15bdb625f5e7f8aef3d24 Signed-off-by: Junghyun Yeon --- diff --git a/src/tpk/step/filesystem/step_tpk_prepare_package_directory.cc b/src/tpk/step/filesystem/step_tpk_prepare_package_directory.cc index ba3eeac..5f0f5e5 100644 --- a/src/tpk/step/filesystem/step_tpk_prepare_package_directory.cc +++ b/src/tpk/step/filesystem/step_tpk_prepare_package_directory.cc @@ -19,6 +19,20 @@ namespace ci = common_installer; namespace tpk { namespace filesystem { +ci::Step::Status StepTpkPreparePackageDirectory::BackupDirectory( + const std::string& entry, const bf::path& backup_path) { + if (!bf::exists(context_->pkg_path.get() / entry)) + return Status::OK; + if (!ci::MoveDir(context_->pkg_path.get() / entry, backup_path, + ci::FSFlag::FS_MERGE_OVERWRITE | ci::FSFlag::FS_COMMIT_COPY_FILE)) { + LOG(ERROR) << "Failed to backup file"; + return Status::APP_DIR_ERROR; + } + + backupPath_ = backup_path; + return Status::OK; +} + ci::Step::Status StepTpkPreparePackageDirectory::PrepareDirectory( const std::string& entry) { // Due to the fact that boost fails to return correct parent_path() then path @@ -64,8 +78,19 @@ ci::Step::Status StepTpkPreparePackageDirectory::PrepareLink( ci::Step::Status StepTpkPreparePackageDirectory::ExtractEntries() { LOG(DEBUG) << "Extracting entries from zip package..."; + bf::path backup_path = + ci::GetBackupPathForPackagePath(context_->pkg_path.get()); + if (context_->request_type.get() == ci::RequestType::MountUpdate && + context_->recovery_info.get().recovery_file) { + context_->recovery_info.get().recovery_file->set_unpacked_dir(backup_path); + context_->recovery_info.get().recovery_file->WriteAndCommitFileContent(); + } + for (auto& entry : tpk::GetExtractEntries()) { LOG(DEBUG) << "Extracting: " << entry; + if (context_->request_type.get() == ci::RequestType::MountUpdate) + if (BackupDirectory(entry, backup_path) != Status::OK) + return Status::APP_DIR_ERROR; auto status = PrepareDirectory(entry); if (status != Status::OK) return status; @@ -100,5 +125,28 @@ ci::Step::Status StepTpkPreparePackageDirectory::precheck() { return Status::OK; } +ci::Step::Status StepTpkPreparePackageDirectory::clean() { + if (!backupPath_.empty()) + ci::RemoveAll(backupPath_); + + return Status::OK; +} + +ci::Step::Status StepTpkPreparePackageDirectory::undo() { + if (backupPath_.empty()) + return Status::OK; + + for (auto& entry : tpk::GetExtractEntries()) { + ci::RemoveAll(context_->pkg_path.get() / entry); + if (!bf::exists(backupPath_ / entry)) + continue; + ci::MoveDir(backupPath_ / entry, context_->pkg_path.get() / entry, + ci::FSFlag::FS_MERGE_OVERWRITE | ci::FSFlag::FS_COMMIT_COPY_FILE); + } + ci::RemoveAll(backupPath_); + return Status::OK; +} + + } // namespace filesystem } // namespace tpk diff --git a/src/tpk/step/filesystem/step_tpk_prepare_package_directory.h b/src/tpk/step/filesystem/step_tpk_prepare_package_directory.h index c08372d..b27cf7f 100644 --- a/src/tpk/step/filesystem/step_tpk_prepare_package_directory.h +++ b/src/tpk/step/filesystem/step_tpk_prepare_package_directory.h @@ -48,16 +48,20 @@ class TPK_BACKEND_EXPORT_API StepTpkPreparePackageDirectory using Step::Step; Status process() override; - Status clean() override { return Status::OK; } - Status undo() override { return Status::OK; } + Status clean() override; + Status undo() override; Status precheck() override; protected: + Status BackupDirectory(const std::string& entry, + const boost::filesystem::path& backup_path); Status PrepareDirectory(const std::string& entry); Status PrepareLinks(); Status ExtractEntries(); Status PrepareLink(const std::string& entry, const boost::filesystem::path& mount_point); + private: + boost::filesystem::path backupPath_; STEP_NAME(TpkPreparePackageDirectory) };