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);
117 bool createDir(const bf::path& path);
118 bool copyDir(const bf::path& path, const bf::path& dst, FSFlag flags = FS_NONE, bool skip_symlink = false);
119 bool copyFile(const bf::path& path, const bf::path& dst);
120 bool moveFile(const bf::path& path, const bf::path& dst, bool force);
121 bool removeFile(const bf::path& path);
122 bool removeAll(const bf::path& path);
124 #endif /* __UTILS_H__ */