1 // Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/filesystem/step_create_res_control_directories.h"
7 #include <boost/filesystem/path.hpp>
11 #include "common/utils/file_util.h"
13 namespace bf = boost::filesystem;
14 namespace ci = common_installer;
18 constexpr char kAllowedDir[] = "res/mount/allowed";
19 constexpr char kGlobalDir[] = "res/mount/global";
20 constexpr char kWorkDir[] = "res/mount/work";
22 bool CreateResControlDirs(const bf::path& root) {
23 if (!ci::CreateDir(root / kAllowedDir))
25 if (!ci::CreateDir(root / kGlobalDir))
27 if (!ci::CreateDir(root / kWorkDir))
32 bool RemoveResControlDirs(const bf::path& root) {
33 if (!ci::RemoveAll(root / kAllowedDir))
35 if (!ci::RemoveAll(root / kGlobalDir))
37 if (!ci::RemoveAll(root / kWorkDir))
44 namespace common_installer {
45 namespace filesystem {
47 Step::Status StepCreateResControlDirectories::precheck() {
48 if (context_->GetPkgPath().empty()) {
49 LOG(ERROR) << "Failed to get pkg root directory";
50 return Status::APP_DIR_ERROR;
55 Step::Status StepCreateResControlDirectories::process() {
56 bf::path root = context_->GetPkgPath();
57 // TODO(jeremy.jang): check the package has res-control tag (+ update case)
58 if (!CreateResControlDirs(root)) {
59 LOG(ERROR) << "Failed to create res-control directories";
60 return Status::APP_DIR_ERROR;
65 Step::Status StepCreateResControlDirectories::undo() {
66 bf::path root = context_->GetPkgPath();
67 if (!RemoveResControlDirs(root)) {
68 LOG(ERROR) << "Failed to remove res-control directories";
69 return Status::APP_DIR_ERROR;
74 } // namespace filesystem
75 } // namespace common_installer