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 check the file is managed assembly or not.
95 * @param[in] file path
96 * @return return true when the file is managed assembly.
97 * otherwise return false including native image case.
99 bool isManagedAssembly(const std::string& filePath);
102 * @brief check the file is native image or not.
103 * @param[in] file path
104 * @return return true when the file is native image.
106 bool isNativeImage(const std::string& filePath);
109 * @brief find assembly files in the directories
110 * @param[in] directories
111 * @param[out] ":" seperated assembly path list
113 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
116 * @brief function pointer for file reader
118 typedef std::function<void (const std::string&, const char*)> FileReader;
121 * @brief scan files in the given directory and run file reader function for that
122 * @param[in] directory
123 * @param[in] file reader function
124 * @param[in] scan depth
126 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
129 * @brief create the new directory.
130 * @param[in] source path
131 * @return return true when the directory was created.
133 bool createDir(const bf::path& path);
136 * @brief copy the directory.
137 * @param[in] path to the source directory
138 * @param[in] path to the target directory
139 * @param[in] filesystem flag
140 * @return return true when the directory was copied.
142 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE);
145 * @brief copy the file.
146 * @param[in] path to the source file
147 * @param[in] path to the target file
148 * @return return true when the file was copied.
150 bool copyFile(const bf::path& path1, const bf::path& path2);
153 * @brief moves of renames the file or directory.
154 * @param[in] path to the source file
155 * @param[in] path to the target file
156 * @return return true when the file was moved.
158 bool moveFile(const bf::path& path1, const bf::path& path2);
161 * @brief removes the file or empty directory.
162 * @param[in] source path
163 * @return return true when the file was deleted.
165 bool removeFile(const bf::path& path);
168 * @brief removes the file or directory and all its contents.
169 * @param[in] source path
170 * @return return true when the file or directory was deleted.
172 bool removeAll(const bf::path& path);
174 #endif /* __UTILS_H__ */