From 83342c22c561b897a0bf5296265c0e9c8054d8b5 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 3 Jun 2021 16:00:17 +0900 Subject: [PATCH] Create directory for res control if necessary Create directories used for res control when a application has res control Change-Id: I9707db1705c97f0b458126fc466c696f41ce69d8 Signed-off-by: Ilho Kim --- .../step_create_res_control_directories.cc | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/common/step/filesystem/step_create_res_control_directories.cc b/src/common/step/filesystem/step_create_res_control_directories.cc index 9b0dee3..fd68f35 100644 --- a/src/common/step/filesystem/step_create_res_control_directories.cc +++ b/src/common/step/filesystem/step_create_res_control_directories.cc @@ -9,6 +9,7 @@ #include #include "common/utils/file_util.h" +#include "common/utils/glist_range.h" namespace bf = boost::filesystem; namespace ci = common_installer; @@ -34,6 +35,18 @@ bool RemoveResControlDirs(const bf::path& root) { return true; } +bool HasResControl(manifest_x* manifest) { + GList* applications = manifest->application; + if (!applications) + return false; + + for (application_x* app : GListRange(applications)) { + if (app->res_control) + return true; + } + return false; +} + } // namespace namespace common_installer { @@ -44,12 +57,19 @@ Step::Status StepCreateResControlDirectories::precheck() { LOG(ERROR) << "Failed to get pkg root directory"; return Status::APP_DIR_ERROR; } + + if (!context_->manifest_data.get()) { + LOG(ERROR) << "manifest_data attribute is empty"; + return Status::MANIFEST_NOT_FOUND; + } return Status::OK; } Step::Status StepCreateResControlDirectories::process() { + if (!HasResControl(context_->manifest_data.get())) + return Status::OK; + 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; @@ -58,6 +78,9 @@ Step::Status StepCreateResControlDirectories::process() { } Step::Status StepCreateResControlDirectories::undo() { + if (!HasResControl(context_->manifest_data.get())) + return Status::OK; + bf::path root = context_->GetPkgPath(); if (!RemoveResControlDirs(root)) { LOG(ERROR) << "Failed to remove res-control directories"; -- 2.7.4