Create directory for res control if necessary 81/259381/5
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 3 Jun 2021 07:00:17 +0000 (16:00 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 17 Jun 2021 05:15:35 +0000 (14:15 +0900)
Create directories used for res control when a application has res control

Change-Id: I9707db1705c97f0b458126fc466c696f41ce69d8
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/step/filesystem/step_create_res_control_directories.cc

index 9b0dee3..fd68f35 100644 (file)
@@ -9,6 +9,7 @@
 #include <string>
 
 #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<application_x*>(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";