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/utils/paths.h"
7 #include <manifest_parser/utils/logging.h>
10 #include <tzplatform_config.h>
11 #include <storage-internal.h>
16 #include "common/utils/user_util.h"
18 namespace ci = common_installer;
19 namespace fs = std::filesystem;
23 const char kImageDir[] = ".image";
24 const char kBckExtension[] = ".bck";
26 std::filesystem::path GetBackupPath(const std::filesystem::path& pkg_path) {
27 fs::path backup_path = pkg_path;
28 backup_path += kBckExtension;
34 namespace common_installer {
36 std::filesystem::path GetBackupPathForPackagePath(
37 const std::filesystem::path& pkg_path) {
38 return GetBackupPath(pkg_path);
41 std::filesystem::path GetBackupPathForManifestFile(
42 const std::filesystem::path& manifest_path) {
43 return GetBackupPath(manifest_path);
46 std::filesystem::path GetBackupPathForIconFile(
47 const std::filesystem::path& icon_path) {
48 return GetBackupPath(icon_path);
51 std::string GetIconFileBackupExtension() {
55 std::filesystem::path GetBackupPathForZipFile(const fs::path& zip_path) {
56 return GetBackupPath(zip_path);
59 std::filesystem::path GetMountLocation(const fs::path& pkg_path) {
60 return pkg_path / ".pkg";
63 std::filesystem::path GetZipPackageLocation(
64 const std::filesystem::path& pkg_path,
65 const std::string& pkgid) {
66 return pkg_path / kImageDir / pkgid;
69 std::filesystem::path GetExternalCardPath() {
70 char* sdpath = nullptr;
74 ret = storage_get_primary_sdcard(&storage_id, &sdpath);
75 if (ret != STORAGE_ERROR_NONE) {
81 std::string mount_path(sdpath);
83 return fs::path(mount_path);
89 std::filesystem::path GetExternalTepPath(RequestMode request_mode,
92 fs::path ext_mount_path = GetExternalCardPath();
93 if (fs::is_empty(ext_mount_path))
95 result = ext_mount_path / "tep";
96 if (request_mode == RequestMode::USER)
97 result /= ci::GetUsernameByUid(uid);
101 std::filesystem::path GetInternalTepPath(
102 const std::filesystem::path& pkg_path) {
103 return pkg_path / "tep";
106 std::filesystem::path GetIconPath(const fs::path& base_path,
107 const std::string& pkgid,
108 const fs::path& icon_filename,
109 const fs::path& root_path) {
110 std::vector<fs::path> paths;
111 fs::path system_path = base_path / icon_filename;
112 fs::path small_system_path = base_path / "default" / "small" / icon_filename;
113 fs::path res_path = root_path / pkgid / "res" / "icons" / icon_filename;
115 paths.push_back(system_path);
116 paths.push_back(small_system_path);
117 paths.push_back(res_path);
119 for (auto& path : paths) {
120 if (fs::exists(path))
127 bool IsExtendedStorageAvailable() {
128 bool is_available = false;
129 int ret = storage_foreach_device_supported(
130 [](int, storage_type_e type, storage_state_e state,
131 const char* path, void* user_data) -> bool {
132 if (type != STORAGE_TYPE_EXTENDED_INTERNAL)
134 if (state != STORAGE_STATE_MOUNTED)
136 bool* available = static_cast<bool*>(user_data);
137 if (fs::exists(path))
143 if (ret != STORAGE_ERROR_NONE) {
144 LOG(ERROR) << "Failed to call storage_foreach_device_supported()";
150 } // namespace common_installer