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>
9 #include <boost/filesystem/operations.hpp>
12 #include <tzplatform_config.h>
13 #include <storage-internal.h>
17 #include "common/utils/user_util.h"
19 namespace bf = boost::filesystem;
20 namespace ci = common_installer;
24 const char kImageDir[] = ".image";
25 const char kBckExtension[] = ".bck";
27 boost::filesystem::path GetBackupPath(const boost::filesystem::path& pkg_path) {
28 bf::path backup_path = pkg_path;
29 backup_path += kBckExtension;
35 namespace common_installer {
37 boost::filesystem::path GetBackupPathForPackagePath(
38 const boost::filesystem::path& pkg_path) {
39 return GetBackupPath(pkg_path);
42 boost::filesystem::path GetBackupPathForManifestFile(
43 const boost::filesystem::path& manifest_path) {
44 return GetBackupPath(manifest_path);
47 boost::filesystem::path GetBackupPathForIconFile(
48 const boost::filesystem::path& icon_path) {
49 return GetBackupPath(icon_path);
52 std::string GetIconFileBackupExtension() {
56 boost::filesystem::path GetBackupPathForZipFile(const bf::path& zip_path) {
57 return GetBackupPath(zip_path);
60 boost::filesystem::path GetMountLocation(const bf::path& pkg_path) {
61 return pkg_path / ".pkg";
64 boost::filesystem::path GetZipPackageLocation(
65 const boost::filesystem::path& pkg_path,
66 const std::string& pkgid) {
67 return pkg_path / kImageDir / pkgid;
70 boost::filesystem::path GetExternalCardPath() {
71 char* sdpath = nullptr;
75 ret = storage_get_primary_sdcard(&storage_id, &sdpath);
76 if (ret != STORAGE_ERROR_NONE) {
82 std::string mount_path(sdpath);
84 return bf::path(mount_path);
90 boost::filesystem::path GetExternalTepPath(RequestMode request_mode,
93 bf::path ext_mount_path = GetExternalCardPath();
94 if (bf::is_empty(ext_mount_path))
96 result = ext_mount_path / "tep";
97 if (request_mode == RequestMode::USER)
98 result /= ci::GetUsernameByUid(uid);
102 boost::filesystem::path GetInternalTepPath(
103 const boost::filesystem::path& pkg_path) {
104 return pkg_path / "tep";
107 boost::filesystem::path GetIconPath(const bf::path& base_path,
108 const std::string& pkgid,
109 const bf::path& icon_filename,
110 const bf::path& root_path) {
111 std::vector<bf::path> paths;
112 bf::path system_path = base_path / icon_filename;
113 bf::path small_system_path = base_path / "default" / "small" / icon_filename;
114 bf::path res_path = root_path / pkgid / "res" / "icons" / icon_filename;
116 paths.push_back(system_path);
117 paths.push_back(small_system_path);
118 paths.push_back(res_path);
120 for (auto& path : paths) {
121 if (bf::exists(path))
128 bool IsExtendedStorageAvailable() {
129 bool is_available = false;
130 int ret = storage_foreach_device_supported(
131 [](int, storage_type_e type, storage_state_e state,
132 const char* path, void* user_data) -> bool {
133 if (type != STORAGE_TYPE_EXTENDED_INTERNAL)
135 if (state != STORAGE_STATE_MOUNTED)
137 bool* available = static_cast<bool*>(user_data);
138 if (bf::exists(path))
144 if (ret != STORAGE_ERROR_NONE) {
145 LOG(ERROR) << "Failed to call storage_foreach_device_supported()";
151 } // namespace common_installer