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 #ifndef PATH_SEPARATOR
26 #define PATH_SEPARATOR '/'
29 namespace bf = boost::filesystem;
30 namespace bs = boost::system;
34 FS_MERGE_SKIP = (1 << 0),
35 FS_MERGE_OVERWRITE = (1 << 1),
36 FS_COMMIT_COPY_FILE = (1 << 2),
37 FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3)
40 bool cmdOptionExists(char** begin, char** end, const std::string& option);
43 * @brief get current executable path
44 * return std::string path
46 std::string readSelfPath();
49 * @brief concat path with PATH_SEPARATOR
50 * @param[in] destination path
51 * @param[in] source path
52 * return std::string result path
54 std::string concatPath(const std::string& path1, const std::string& path2);
57 * @brief get absolute Path
58 * @param[in] source path
59 * return std::string result path
61 std::string absolutePath(const std::string& path);
64 * @brief get the directory of file
65 * @param[in] source path
66 * return std::string result path
68 std::string baseName(const std::string& path);
71 * @brief get root path
72 * @param[in] package id
73 * @param[out] root path
75 int getRootPath(std::string pkgId, std::string& rootPath);
78 * @brief split path with ":" delimiter and put that in the vector
79 * @param[in] source path
80 * @param[out] string vector
82 void splitPath(const std::string& path, std::vector<std::string>& out);
85 * @brief check file is exist
86 * @param[in] source path
89 bool isFileExist(const std::string& path);
92 * @brief check the file is managed assembly or not.
93 * @param[in] file path
94 * @return return true when the file is managed assembly.
95 * otherwise return false including native image case.
97 bool isManagedAssembly(const std::string& filePath);
100 * @brief check the file is native image or not.
101 * @param[in] file path
102 * @return return true when the file is native image.
104 bool isNativeImage(const std::string& filePath);
107 * @brief find assembly files in the directories
108 * @param[in] directories
109 * @param[out] ":" seperated assembly path list
111 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
114 * @brief function pointer for file reader
116 typedef std::function<void (const std::string&, const char*)> FileReader;
119 * @brief scan files in the given directory and run file reader function for that
120 * @param[in] directory
121 * @param[in] file reader function
122 * @param[in] scan depth
124 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
127 * @brief create the new directory.
128 * @param[in] source path
129 * @return return true when the directory was created.
131 bool createDir(const bf::path& path);
134 * @brief copy the directory.
135 * @param[in] path to the source directory
136 * @param[in] path to the target directory
137 * @param[in] filesystem flag
138 * @return return true when the directory was copied.
140 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE);
143 * @brief copy the file.
144 * @param[in] path to the source file
145 * @param[in] path to the target file
146 * @return return true when the file was copied.
148 bool copyFile(const bf::path& path1, const bf::path& path2);
151 * @brief moves of renames the file or directory.
152 * @param[in] path to the source file
153 * @param[in] path to the target file
154 * @return return true when the file was moved.
156 bool moveFile(const bf::path& path1, const bf::path& path2);
159 * @brief removes the file or empty directory.
160 * @param[in] source path
161 * @return return true when the file was deleted.
163 bool removeFile(const bf::path& path);
166 * @brief removes the file or directory and all its contents.
167 * @param[in] source path
168 * @return return true when the file or directory was deleted.
170 bool removeAll(const bf::path& path);
172 #endif /* __UTILS_H__ */