From 3adc54041cb52561d7170ca7aa47525e153e66c8 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 25 May 2021 13:25:32 +0900 Subject: [PATCH] Add a new step StepCreateResControlDirectories This step creates directories for res-control feature. Change-Id: I168c9485246fda09251c894859f2ee3e48a9f629 Signed-off-by: Sangyoon Jang --- src/common/installer/app_installer.cc | 8 +++ .../step_create_res_control_directories.cc | 75 ++++++++++++++++++++++ .../step_create_res_control_directories.h | 42 ++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/common/step/filesystem/step_create_res_control_directories.cc create mode 100644 src/common/step/filesystem/step_create_res_control_directories.h diff --git a/src/common/installer/app_installer.cc b/src/common/installer/app_installer.cc index cd8df73..cafc726 100644 --- a/src/common/installer/app_installer.cc +++ b/src/common/installer/app_installer.cc @@ -35,6 +35,7 @@ #include "common/step/filesystem/step_copy_tep.h" #include "common/step/filesystem/step_create_globalapp_symlinks.h" #include "common/step/filesystem/step_create_icons.h" +#include "common/step/filesystem/step_create_res_control_directories.h" #include "common/step/filesystem/step_create_storage_directories.h" #include "common/step/filesystem/step_delta_patch.h" #include "common/step/filesystem/step_disable_external_mount.h" @@ -327,6 +328,7 @@ void AppInstaller::InstallSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL); AddStep( @@ -366,6 +368,7 @@ void AppInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); AddStep( @@ -429,6 +432,7 @@ void AppInstaller::ReinstallSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); AddStep( @@ -471,6 +475,7 @@ void AppInstaller::DeltaSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); AddStep( @@ -597,6 +602,7 @@ void AppInstaller::ManifestDirectInstallSteps() { AddStep(true); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); @@ -622,6 +628,7 @@ void AppInstaller::ManifestDirectUpdateSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); @@ -718,6 +725,7 @@ void AppInstaller::ReadonlyUpdateInstallSteps() { AddStep(); AddStep(); AddStep(); + AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); AddStep( diff --git a/src/common/step/filesystem/step_create_res_control_directories.cc b/src/common/step/filesystem/step_create_res_control_directories.cc new file mode 100644 index 0000000..fed6f09 --- /dev/null +++ b/src/common/step/filesystem/step_create_res_control_directories.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2021 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 "common/step/filesystem/step_create_res_control_directories.h" + +#include + +#include + +#include "common/utils/file_util.h" + +namespace bf = boost::filesystem; +namespace ci = common_installer; + +namespace { + +constexpr char kAllowedDir[] = "res/mount/allowed"; +constexpr char kGlobalDir[] = "res/mount/global"; +constexpr char kWorkDir[] = "res/mount/work"; + +bool CreateResControlDirs(const bf::path& root) { + if (!ci::CreateDir(root / kAllowedDir)) + return false; + if (!ci::CreateDir(root / kGlobalDir)) + return false; + if (!ci::CreateDir(root / kWorkDir)) + return false; + return true; +} + +bool RemoveResControlDirs(const bf::path& root) { + if (!ci::RemoveAll(root / kAllowedDir)) + return false; + if (!ci::RemoveAll(root / kGlobalDir)) + return false; + if (!ci::RemoveAll(root / kWorkDir)) + return false; + return true; +} + +} // namespace + +namespace common_installer { +namespace filesystem { + +Step::Status StepCreateResControlDirectories::precheck() { + if (context_->GetPkgPath().empty()) { + LOG(ERROR) << "Failed to get pkg root directory"; + return Status::APP_DIR_ERROR; + } + return Status::OK; +} + +Step::Status StepCreateResControlDirectories::process() { + bf::path root = context_->GetPkgPath(); + // TODO(jeremy.jang): check the package has res-control tag (+ update case) + if (!CreateResControlDirs(root)) { + LOG(ERROR) << "Failed to create res-control directories"; + return Status::APP_DIR_ERROR; + } + return Status::OK; +} + +Step::Status StepCreateResControlDirectories::undo() { + bf::path root = context_->GetPkgPath(); + if (!RemoveResControlDirs(root)) { + LOG(ERROR) << "Failed to remove res-control directories"; + return Status::APP_DIR_ERROR; + } + return Status::OK; +} + +} // namespace filesystem +} // namespace common_installer diff --git a/src/common/step/filesystem/step_create_res_control_directories.h b/src/common/step/filesystem/step_create_res_control_directories.h new file mode 100644 index 0000000..0bd2943 --- /dev/null +++ b/src/common/step/filesystem/step_create_res_control_directories.h @@ -0,0 +1,42 @@ +// Copyright (c) 2021 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 COMMON_STEP_FILESYSTEM_STEP_CREATE_RES_CONTROL_DIRECTORIES_H_ +#define COMMON_STEP_FILESYSTEM_STEP_CREATE_RES_CONTROL_DIRECTORIES_H_ + +#include + +#include "common/step/step.h" + +namespace common_installer { +namespace filesystem { + +/** + * \brief Installation. + * Responsible for creating res-control directories + * + * * process method implements creation of res-control directories for + * package. + * + * res/mount/allowed: mount point for allowed resources + * res/mount/global: mount point for global resources + * res/mount/work: for working directory + */ +class StepCreateResControlDirectories : public common_installer::Step { + public: + using Step::Step; + + Status process() override; + Status clean() override { return Status::OK; } + Status undo() override; + Status precheck() override; + + private: + STEP_NAME(CreateResControlDirectories) +}; + +} // namespace filesystem +} // namespace common_installer + +#endif // COMMON_STEP_FILESYSTEM_STEP_CREATE_RES_CONTROL_DIRECTORIES_H_ -- 2.7.4