2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <boost/filesystem.hpp>
25 #include <launcher_env.h>
27 #ifndef PATH_SEPARATOR
28 #define PATH_SEPARATOR '/'
31 namespace bf = boost::filesystem;
32 namespace bs = boost::system;
36 FS_MERGE_SKIP = (1 << 0),
37 FS_MERGE_OVERWRITE = (1 << 1),
38 FS_COMMIT_COPY_FILE = (1 << 2),
39 FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3)
42 bool cmdOptionExists(char** begin, char** end, const std::string& option);
45 * @brief get current executable path
46 * return std::string path
48 std::string readSelfPath();
51 * @brief concat path with PATH_SEPARATOR
52 * @param[in] destination path
53 * @param[in] source path
54 * return std::string result path
56 std::string concatPath(const std::string& path1, const std::string& path2);
59 * @brief get absolute Path
60 * @param[in] source path
61 * return std::string result path
63 std::string absolutePath(const std::string& path);
66 * @brief get the directory of file
67 * @param[in] source path
68 * return std::string result path
70 std::string baseName(const std::string& path);
73 * @brief get root path
74 * @param[in] package id
75 * @param[out] root path
77 int getRootPath(std::string pkgId, std::string& rootPath);
80 * @brief split path with ":" delimiter and put that in the vector
81 * @param[in] source path
82 * @param[out] string vector
84 void splitPath(const std::string& path, std::vector<std::string>& out);
87 * @brief check file is exist
88 * @param[in] source path
91 bool isFileExist(const std::string& path);
94 * @brief get file size
95 * @param[in] source path
96 * @return size of file
98 uintptr_t getFileSize(const std::string& path);
101 * @brief check the file is managed assembly or not.
102 * @param[in] file path
103 * @return return true when the file is managed assembly.
104 * otherwise return false including native image case.
106 bool isManagedAssembly(const std::string& filePath);
109 * @brief check the file is native image or not.
110 * @param[in] file path
111 * @return return true when the file is native image.
113 bool isNativeImage(const std::string& filePath);
116 * @brief find assembly files in the directories
117 * @param[in] directories
118 * @param[out] ":" seperated assembly path list
120 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
123 * @brief function pointer for file reader
125 typedef std::function<void (const std::string&, const char*)> FileReader;
128 * @brief scan files in the given directory and run file reader function for that
129 * @param[in] directory
130 * @param[in] file reader function
131 * @param[in] scan depth
133 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
136 * @brief create the new directory.
137 * @param[in] source path
138 * @return return true when the directory was created.
140 bool createDir(const bf::path& path);
143 * @brief update assembly file info.
144 * @param[in] get path
145 * @param[in] set path
147 void updateAssemblyInfo(const std::string& getPath, const std::string& setPath);
150 * @brief copy the directory.
151 * @param[in] path to the source directory
152 * @param[in] path to the target directory
153 * @param[in] filesystem flag
154 * @return return true when the directory was copied.
156 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE);
159 * @brief copy the file.
160 * @param[in] path to the source file
161 * @param[in] path to the target file
162 * @return return true when the file was copied.
164 bool copyFile(const bf::path& path1, const bf::path& path2);
167 * @brief moves of renames the file or directory.
168 * @param[in] path to the source file
169 * @param[in] path to the target file
170 * @return return true when the file was moved.
172 bool moveFile(const bf::path& path1, const bf::path& path2);
175 * @brief removes the file or empty directory.
176 * @param[in] source path
177 * @return return true when the file was deleted.
179 bool removeFile(const bf::path& path);
182 * @brief removes the file or directory and all its contents.
183 * @param[in] source path
184 * @return return true when the file or directory was deleted.
186 bool removeAll(const bf::path& path);
188 #endif /* __UTILS_H__ */