1 // Copyright (c) 2015 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_storage_directories.h"
7 #include <pkgmgrinfo_basic.h>
13 #include "common/privileges.h"
14 #include "common/shared_dirs.h"
15 #include "common/utils/file_util.h"
16 #include "common/utils/glist_range.h"
18 namespace ci = common_installer;
19 namespace fs = std::filesystem;
21 namespace common_installer {
22 namespace filesystem {
24 bool StepCreateStorageDirectories::CreatePerUserStorageDirs(
25 bool trusted, bool shareddata) {
26 LOG(INFO) << "Creating per-user directories for package: "
27 << context_->pkgid.get();
29 bool is_readonly = context_->is_readonly_package.get();
30 if (!CreatePerUserStorageDirectories(context_->pkgid.get(), trusted,
31 shareddata, is_readonly, additional_shared_dirs_)) {
32 LOG(ERROR) << "Failed to create per-user storage directories";
39 bool StepCreateStorageDirectories::CreateStorageDirs(
40 bool trusted, bool shareddata) {
41 if (!CreateStorageDirectories(context_->root_application_path.get(),
42 context_->pkgid.get(), context_->uid.get(),
43 trusted, shareddata)) {
44 LOG(ERROR) << "Failed to create storage directories";
50 bool StepCreateStorageDirectories::DeletePerUserStorageDirs() {
51 return ci::DeletePerUserStorageDirectories(context_->pkgid.get());
54 Step::Status StepCreateStorageDirectories::process() {
56 std::string author_id = context_->certificate_info.get().author_id.get();
57 if (!author_id.empty())
60 manifest_x* manifest = context_->manifest_data.get();
61 bool shareddata = ShouldSupportLegacySharedDataDir(manifest->api_version);
63 for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
64 if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
71 if (context_->request_mode.get() == RequestMode::GLOBAL) {
72 if (!CreatePerUserStorageDirs(trusted, shareddata))
73 return Status::APP_DIR_ERROR;
75 if (!CreateStorageDirs(trusted, shareddata))
76 return Status::APP_DIR_ERROR;
81 Step::Status StepCreateStorageDirectories::undo() {
82 if (context_->request_mode.get() != RequestMode::GLOBAL)
83 return Step::Status::OK;
85 if (!DeletePerUserStorageDirs()) {
86 LOG(ERROR) << "Failed to delete per user storage directories";
87 return Status::APP_DIR_ERROR;
93 } // namespace filesystem
94 } // namespace common_installer