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)
43 * @brief an iterator to the begin element in the range that compares equal to option
44 * @param[in] begin element
45 * @param[in] end elment
46 * return return true when elements match
48 bool cmdOptionExists(char** begin, char** end, const std::string& option);
51 * @brief get current executable path
52 * return std::string path
54 std::string readSelfPath();
57 * @brief concat path with PATH_SEPARATOR
58 * @param[in] destination path
59 * @param[in] source path
60 * return std::string result path
62 std::string concatPath(const std::string& path1, const std::string& path2);
65 * @brief get absolute Path
66 * @param[in] source path
67 * return std::string result path
69 std::string absolutePath(const std::string& path);
72 * @brief get the directory of file
73 * @param[in] source path
74 * return std::string result path
76 std::string baseName(const std::string& path);
79 * @brief get root path
80 * @param[in] package id
81 * @param[out] root path
83 int getRootPath(std::string pkgId, std::string& rootPath);
86 * @brief get exec name
87 * @param[in] package id
88 * @param[out] exec name
90 int getExecName(std::string pkgId, std::string& execName);
93 * @brief get metadata value
94 * @param[in] package id
95 * @param[in] metadata key
96 * @param[out] metadata value
98 int getMetadataValue(std::string pkgId, std::string metadataKey, std::string& metadataValue);
101 * @brief split path with ":" delimiter and put that in the vector
102 * @param[in] source path
103 * @param[out] string vector
105 void splitPath(const std::string& path, std::vector<std::string>& out);
108 * @brief check file is exist
109 * @param[in] source path
112 bool isFileExist(const std::string& path);
115 * @brief get file size
116 * @param[in] source path
117 * @return size of file
119 uintptr_t getFileSize(const std::string& path);
122 * @brief check the file is managed assembly or not.
123 * @param[in] file path
124 * @return return true when the file is managed assembly.
125 * otherwise return false including native image case.
127 bool isManagedAssembly(const std::string& filePath);
130 * @brief check the file is native image or not.
131 * @param[in] file path
132 * @return return true when the file is native image.
134 bool isNativeImage(const std::string& filePath);
137 * @brief find assembly files in the directories
138 * @param[in] directories
139 * @param[out] ":" seperated assembly path list
141 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
144 * @brief function pointer for file reader
146 typedef std::function<void (const std::string&, const char*)> FileReader;
149 * @brief scan files in the given directory and run file reader function for that
150 * @param[in] directory
151 * @param[in] file reader function
152 * @param[in] scan depth
154 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
157 * @brief update assembly file info.
158 * @param[in] get path
159 * @param[in] set path
160 * @param[in] symbolic link
162 void updateAssemblyInfo(const std::string& getPath, const std::string& setPath, bool isSymlink = false);
165 * @brief create the new directory.
166 * @param[in] source path
167 * @return return true when the directory was created.
169 bool createDir(const bf::path& path);
172 * @brief copy the directory.
173 * @param[in] path to the source directory
174 * @param[in] path to the target directory
175 * @param[in] filesystem flag
176 * @return return true when the directory was copied.
178 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE);
181 * @brief copy the file.
182 * @param[in] path to the source file
183 * @param[in] path to the target file
184 * @return return true when the file was copied.
186 bool copyFile(const bf::path& path1, const bf::path& path2);
189 * @brief moves of renames the file or directory.
190 * @param[in] path to the source file
191 * @param[in] path to the target file
192 * @return return true when the file was moved.
194 bool moveFile(const bf::path& path1, const bf::path& path2);
197 * @brief removes the file or empty directory.
198 * @param[in] source path
199 * @return return true when the file was deleted.
201 bool removeFile(const bf::path& path);
204 * @brief removes the file or directory and all its contents.
205 * @param[in] source path
206 * @return return true when the file or directory was deleted.
208 bool removeAll(const bf::path& path);
210 #endif /* __UTILS_H__ */