From f0dd91560b64b43f03cf4dad701fe382bac1ec08 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 18 Jan 2018 11:14:38 +0900 Subject: [PATCH] Add codes to enable ManifestDirectInstall for mount intalled pkg - Some files should be extracted. - Add Step to determine whether given pkg is mount installed or not. - Override undo() to enable undo operation. Related changes: [app-installers] : https://review.tizen.org/gerrit/167144 Change-Id: I03d22721135e8b3607c5a18f11dc06e9b82ef070 Signed-off-by: Junghyun Yeon --- .../step_wgt_prepare_package_directory.cc | 110 ++++++++++++++++++--- .../step_wgt_prepare_package_directory.h | 7 +- src/wgt/wgt_installer.cc | 3 + 3 files changed, 102 insertions(+), 18 deletions(-) diff --git a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc index d3f53b1..10c44a7 100644 --- a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc +++ b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc @@ -19,42 +19,102 @@ namespace { const char kResWgtDirectory[] = "res/wgt"; +const std::vector kExtractEntries = { + "config.xml", + "index.html", + "author-signature.xml", + "signature1.xml", + "signature2.xml" +}; + +const std::vector& GetExtractEntries() { + return kExtractEntries; +} + } // namespace namespace wgt { namespace filesystem { -ci::Step::Status StepWgtPreparePackageDirectory::CreateSymlinkToMountPoint() { +ci::Step::Status StepWgtPreparePackageDirectory::CreateSymlinks() { bs::error_code error; bf::path mount_point = ci::GetMountLocation(context_->GetPkgPath()); bf::path res_wgt_link = context_->GetPkgPath() / kResWgtDirectory; - if (bf::exists(res_wgt_link)) { - if (!bf::is_symlink(symlink_status(res_wgt_link))) { - LOG(ERROR) << res_wgt_link << " is not symlink. Cannot proceed"; - return Status::APP_DIR_ERROR; - } - bf::remove(res_wgt_link, error); - if (error) { - LOG(ERROR) << "Failed to remote old symlink to wgt resource directory"; - return Status::APP_DIR_ERROR; + + std::vector fileList; + std::vector extractEntries = GetExtractEntries(); + for (bf::directory_iterator iter(mount_point); + iter != bf::directory_iterator(); ++iter) { + bf::path current(iter->path()); + if (std::find(extractEntries.begin(), extractEntries.end(), + current.filename()) != extractEntries.end()) + continue; + + bf::path destination = res_wgt_link / current.filename(); + if (bf::exists(destination)) { + if (!bf::is_symlink(symlink_status(destination))) { + LOG(ERROR) << "Cannot proceed. " + << "Location of link is used by another file"; + return Status::APP_DIR_ERROR; + } + bf::remove(destination, error); + if (error) { + LOG(ERROR) << "Failed to remove previous symlink"; + return Status::APP_DIR_ERROR; + } } - } else { - bf::create_directories(res_wgt_link.parent_path(), error); + bf::create_symlink(iter->path(), destination, error); if (error) { - LOG(ERROR) << "Failed to create " << kResWgtDirectory << " directory"; + LOG(ERROR) << "Failed to create symlink to widget image :" << + boost::system::system_error(error).what(); return Status::APP_DIR_ERROR; } } - bf::create_symlink(mount_point, res_wgt_link, error); + + return Status::OK; +} + +ci::Step::Status StepWgtPreparePackageDirectory::ExtractEntries() { + bf::path backup_path = + ci::GetBackupPathForPackagePath(context_->GetPkgPath()); + backupPath_ = backup_path; + 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(); + } + + bf::path resource_path = context_->GetPkgPath() / kResWgtDirectory; + bs::error_code error; + bf::create_directories(resource_path, error); if (error) { - LOG(ERROR) << "Failed to create symlink to widget image"; + LOG(ERROR) << "Failed to create proper directory structure in widget"; return Status::APP_DIR_ERROR; } + + for (auto& entry : GetExtractEntries()) { + if (context_->request_type.get() == ci::RequestType::MountUpdate) + if (!ci::BackupDir(resource_path, backup_path, entry)) + return Status::APP_DIR_ERROR; + + if (!ci::ExtractToTmpDir(context_->file_path.get().c_str(), + resource_path.c_str(), entry)) { + LOG(ERROR) << "Failed to extract file"; + return Status::UNZIP_ERROR; + } + } + return Status::OK; } ci::Step::Status StepWgtPreparePackageDirectory::process() { - Status status = CreateSymlinkToMountPoint(); + Status status; + + status = ExtractEntries(); + if (status != Status::OK) + return status; + + status = CreateSymlinks(); if (status != Status::OK) return status; LOG(DEBUG) << "Symlink to mount point created"; @@ -70,5 +130,23 @@ ci::Step::Status StepWgtPreparePackageDirectory::precheck() { return Status::OK; } +ci::Step::Status StepWgtPreparePackageDirectory::undo() { + if (backupPath_.empty()) + return Status::OK; + + for (auto& entry : GetExtractEntries()) { + ci::RemoveAll(context_->GetPkgPath() / kResWgtDirectory / entry); + if (!bf::exists(backupPath_ / entry)) + continue; + ci::MoveDir(backupPath_ / entry, + context_->GetPkgPath() / kResWgtDirectory / entry, + ci::FSFlag::FS_MERGE_OVERWRITE | + ci::FSFlag::FS_COMMIT_COPY_FILE | + ci::FSFlag::FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS); + } + ci::RemoveAll(backupPath_); + return Status::OK; +} + } // namespace filesystem } // namespace wgt diff --git a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h index dd98d4c..8b9f14c 100644 --- a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h +++ b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h @@ -30,11 +30,14 @@ class StepWgtPreparePackageDirectory : public common_installer::Step { Status process() override; Status clean() override { return Status::OK; } - Status undo() override { return Status::OK; } + Status undo() override; Status precheck() override; private: - Status CreateSymlinkToMountPoint(); + boost::filesystem::path backupPath_; + + Status ExtractEntries(); + Status CreateSymlinks(); STEP_NAME(WgtPreparePackageDirectory) }; diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 75630c9..056c8b6 100755 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -458,6 +459,7 @@ void WgtInstaller::ManifestDirectInstallSteps() { AddStep( wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -488,6 +490,7 @@ void WgtInstaller::ManifestDirectUpdateSteps() { AddStep(pkgmgr_); AddStep( wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.7.4