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)
41 * @brief get current executable path
42 * return std::string path
44 std::string readSelfPath();
47 * @brief concat path with PATH_SEPARATOR
48 * @param[in] destination path
49 * @param[in] source path
50 * return std::string result path
52 std::string concatPath(const std::string& path1, const std::string& path2);
55 * @brief get absolute Path
56 * @param[in] source path
57 * return std::string result path
59 std::string absolutePath(const std::string& path);
62 * @brief get the directory of file
63 * @param[in] source path
64 * return std::string result path
66 std::string baseName(const std::string& path);
69 * @brief split path with ":" delimiter and put that in the vector
70 * @param[in] source path
71 * @param[out] string vector
73 void splitPath(const std::string& path, std::vector<std::string>& out);
76 * @brief check file is exist
77 * @param[in] source path
80 bool isFileExist(const std::string& path);
83 * @brief check the file is managed assembly or not.
84 * @param[in] file path
85 * @return return true when the file is managed assembly.
86 * otherwise return false including native image case.
88 bool isManagedAssembly(const std::string& filePath);
91 * @brief check the file is native image or not.
92 * @param[in] file path
93 * @return return true when the file is native image.
95 bool isNativeImage(const std::string& filePath);
98 * @brief find assembly files in the directories
99 * @param[in] directories
100 * @param[out] ":" seperated assembly path list
102 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
105 * @brief function pointer for file reader
107 typedef std::function<void (const std::string&, const char*)> FileReader;
110 * @brief scan files in the given directory and run file reader function for that
111 * @param[in] directory
112 * @param[in] file reader function
113 * @param[in] scan depth
115 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
118 * @brief create the new directory.
119 * @param[in] source path
120 * @return return true when the directory was created.
122 bool createDir(const bf::path& path);
125 * @brief copy the directory.
126 * @param[in] path to the source directory
127 * @param[in] path to the target directory
128 * @param[in] filesystem flag
129 * @return return true when the directory was copied.
131 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE);
134 * @brief copy the file.
135 * @param[in] path to the source file
136 * @param[in] path to the target file
137 * @return return true when the file was copied.
139 bool copyFile(const bf::path& path1, const bf::path& path2);
142 * @brief moves of renames the file or directory.
143 * @param[in] path to the source file
144 * @param[in] path to the target file
145 * @return return true when the file was moved.
147 bool moveFile(const bf::path& path1, const bf::path& path2);
150 * @brief removes the file or empty directory.
151 * @param[in] source path
152 * @return return true when the file was deleted.
154 bool removeFile(const bf::path& path);
157 * @brief removes the file or directory and all its contents.
158 * @param[in] source path
159 * @return return true when the file or directory was deleted.
161 bool removeAll(const bf::path& path);
163 #endif /* __UTILS_H__ */