X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=NativeLauncher%2Finc%2Futils.h;h=524264ee3bf15c183240debbb2fb3719d193d2c0;hb=33b4aa2fcbb716d081fc13ac6855fc53bd343532;hp=79e8489bf9dd193276849ef8976cb905a7cec995;hpb=d109edcd7cfe4c685efc306d2a3bfcb7da7d23b3;p=platform%2Fcore%2Fdotnet%2Flauncher.git diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 79e8489..524264e 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -17,43 +17,115 @@ #ifndef __UTILS_H__ #define __UTILS_H__ +#include #include #include #include +#include +#include #include +#include + #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' #endif -/** - * @brief get current executable path - * return std::string path - */ -std::string readSelfPath(); +#ifndef PROFILE_BASENAME +#define PROFILE_BASENAME ".__tizen_specific_profile_data" +#endif + +namespace bf = boost::filesystem; +namespace bs = boost::system; + +enum FSFlag : int { + FS_NONE = 0, + FS_MERGE_SKIP = (1 << 0), + FS_MERGE_OVERWRITE = (1 << 1), + FS_COMMIT_COPY_FILE = (1 << 2), + FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3) +}; + +#ifndef PR_TASK_PERF_USER_TRACE +#define PR_TASK_PERF_USER_TRACE 666 +#endif /** * @brief concat path with PATH_SEPARATOR * @param[in] destination path * @param[in] source path - * return std::string result path + * @return std::string result path */ std::string concatPath(const std::string& path1, const std::string& path2); /** - * @brief get absolute Path + * @brief get canonicalized absolute Path * @param[in] source path - * return std::string result path + * @return std::string result path */ -std::string absolutePath(const std::string& path); +std::string getAbsolutePath(const std::string& path); /** * @brief get the directory of file * @param[in] source path - * return std::string result path + * @return std::string result path + */ +std::string getBaseName(const std::string& path); + +/** + * @brief replaces all matching substrings of the regular expression with a given replacement + * @param[in] original string + * @param[in] pattern to match + * @param[in] replacement string + * @return std::string the modified string + */ +std::string replaceAll(const std::string& str, const std::string& pattern, const std::string& replace); + +/** + * @brief get root path + * @param[in] package id + * @return std::string root path + */ +std::string getRootPath(const std::string& pkgId); + +/** + * @brief get exec name + * @param[in] package id + * @return std::string exec name + */ +std::string getExecName(const std::string& pkgId); + +/** + * @brief get app type + * @param[in] package id + * @return std::string app type + */ +std::string getAppType(const std::string& pkgId); + +/** + * @brief get metadata value + * @param[in] package id + * @param[in] metadata key + * @return std::string metadata value */ -std::string baseName(const std::string& path); +std::string getMetadataValue(const std::string& pkgId, const std::string& key); + +/** + * @brief change the extension of a path or file + * @param[in] source path or file + * @param[in] from extension + * @param[in] to extension + * @return std::string path or file with changed extension + */ +std::string changeExtension(const std::string& path, const std::string& from, const std::string& to); + +/** + * @brief check the path is 'readonly' or not + * @param[in] path + * @return bool package readonly value + */ +bool isReadOnlyArea(const std::string& path); /** * @brief split path with ":" delimiter and put that in the vector @@ -63,11 +135,26 @@ std::string baseName(const std::string& path); void splitPath(const std::string& path, std::vector& out); /** - * @brief check file is exist + * @brief check file exists + * in case of symlink file, check both input file and link reference file. * @param[in] source path * @return bool */ -bool isFileExist(const std::string& path); +bool isFile(const std::string& path); + +/** + * @brief check symlink file + * @param[in] source path + * @return bool + */ +bool isSymlinkFile(const std::string& path); + +/** + * @brief check directory exists + * @param[in] source path + * @return bool + */ +bool isDirectory(const std::string& path); /** * @brief check the file is managed assembly or not. @@ -78,30 +165,158 @@ bool isFileExist(const std::string& path); bool isManagedAssembly(const std::string& filePath); /** - * @brief check the file is native image or not. + * @brief Resolve assembly files from directories and append their paths to the given list. + * @remark If a native image exists for an assembly in the same directory, it will be used. + * If multiple assemblies of the same name exist, the first one will be used. + * @param[in] directories list of directories + * @param[out] list colon-separated string of assembly paths + */ +void addAssembliesFromDirectories(const std::vector& directories, std::string& list); + +/** + * @brief File search callback + * @param[in] path full path to a resolved file + * @param[in] filename file name + */ +typedef std::function FileReader; + +/** + * @brief Scan all files in the given directory. + * @param[in] directory path to a root directory + * @param[in] reader callback for iteration + * @param[in] depth recursive search depth + */ +void scanFilesInDirectory(const std::string& directory, FileReader reader, unsigned int depth); + +/** + * @brief copy smack and ownership. + * @param[in] get path + * @param[in] set path + * @param[in] symbolic link + */ +void copySmackAndOwnership(const std::string& fromPath, const std::string& toPath, bool isSymlink = false); + +/** + * @brief check whether the path exists or not. + * @param[in] source path + * @return return true when the path exist. + */ +bool exist(const bf::path& path); + +/** + * @brief create the new directory. + * @param[in] source path + * @return return true when the directory was created. + */ +bool createDir(const bf::path& path); + +/** + * @brief copy the directory. + * @param[in] path to the source directory + * @param[in] path to the target directory + * @param[in] filesystem flag + * @return return true when the directory was copied. + */ +bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags = FS_NONE); + +/** + * @brief copy the file. + * @param[in] path to the source file + * @param[in] path to the target file + * @return return true when the file was copied. + */ +bool copyFile(const bf::path& path1, const bf::path& path2); + +/** + * @brief moves of renames the file or directory. + * @param[in] path to the source file + * @param[in] path to the target file + * @return return true when the file was moved. + */ +bool moveFile(const bf::path& path1, const bf::path& path2); + +/** + * @brief removes the file or empty directory. + * @param[in] source path + * @return return true when the file was deleted. + */ +bool removeFile(const bf::path& path); + +/** + * @brief removes the file or directory and all its contents. + * @param[in] source path + * @return return true when the file or directory was deleted. + */ +bool removeAll(const bf::path& path); + +/** + * @brief change command name of the current process for access via ps command + * @param[in] name + */ +void setCmdName(const std::string& name); + +/** + * @brief Get the file name from the specified path. + * @remark An empty string will be returned if the path string ends with a path separator character. + * @param[in] path path to a file + * @return a substring after the path separator character + */ +std::string getFileName(const std::string& path); + +/** + * @brief Generates a representation called a message digest * @param[in] file path - * @return return true when the file is native image. + * @return message digest + */ +std::string SHA256(const std::string& path); + +/** + * @brief Creates the package information handle from db which is not disabled. + * This function is a wrapper of pkgmgrinfo_pkginfo_get_pkginfo() to handle multi-user case + * @param[in] pkg id + * @param[out] pkginfo handle + * @return 0 if success, otherwise -1 + */ +int pkgmgrGetPkgInfo(const std::string& pkgId, pkgmgrinfo_pkginfo_h* handle); + +/** + * @brief Creates the application information handle from db. + * This function is a wrapper of pkgmgrinfo_appinfo_get_appinfo() to handle multi-user case + * @param[in] app id + * @param[out] appinfo handle + * @return 0 if success, otherwise -1 + */ +int pkgmgrGetAppInfo(const std::string& appId, pkgmgrinfo_appinfo_h* handle); + +/** + * @brief Executes the metadata filter query for all the installed packages. + * This function is a wrapper of pkgmgrinfo_appinfo_metadata_filter_foreach() to handle multi-user case + * @param[in] metadata filter handle + * @param[in] callback function + * @param[in] user data + * @return 0 if success, otherwise -1 */ -bool isNativeImage(const std::string& filePath); +int pkgmgrMDFilterForeach(pkgmgrinfo_appinfo_metadata_filter_h handle, + pkgmgrinfo_app_list_cb app_cb, + void *user_data); /** - * @brief find assembly files in the directories - * @param[in] directories - * @param[out] ":" seperated assembly path list + * @brief Prints HW Clock log + * @param[in] format `printf`-like format string + * @param[in] ... `printf`-like variadic list of arguments corresponding to the format string */ -void assembliesInDirectory(const std::vector& directories, std::string& tpaList); +void printHWClockLog(const char* format, ...); /** - * @brief function pointer for file reader + * @brief Return NCDB startup hook + * @return NCDB startup hook */ -typedef std::function FileReader; +const char* getNCDBStartupHook(); /** - * @brief scan files in the given directory and run file reader function for that - * @param[in] directory - * @param[in] file reader function - * @param[in] scan depth + * @brief Check is NCDB startup hook provided in DOTNET_STARTUP_HOOKS env + * @return `true` if provided, otherwise `false` */ -void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth); +bool isNCDBStartupHookProvided(); #endif /* __UTILS_H__ */