Refactoring the dotnettool (#231)
[platform/core/dotnet/launcher.git] / NativeLauncher / inc / utils.h
index 6baf0ad..90cc23d 100644 (file)
@@ -21,7 +21,6 @@
 #include <vector>
 #include <functional>
 #include <boost/filesystem.hpp>
-#include <sqlite3.h>
 
 #include <launcher_env.h>
 
@@ -122,6 +121,13 @@ void splitPath(const std::string& path, std::vector<std::string>& out);
 bool isFileExist(const std::string& path);
 
 /**
+ * @brief check directory is exist
+ * @param[in] source path
+ * @return bool
+ */
+bool isDirectoryExist(const std::string& path);
+
+/**
  * @brief get file size
  * @param[in] source path
  * @return size of file
@@ -144,32 +150,36 @@ bool isManagedAssembly(const std::string& filePath);
 bool isNativeImage(const std::string& filePath);
 
 /**
- * @brief find assembly files in the directories
- * @param[in] directories
- * @param[out] ":" seperated assembly path list
+ * @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 assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList);
+void addAssembliesFromDirectories(const std::vector<std::string>& directories, std::string& list);
 
 /**
- * @brief function pointer for file reader
+ * @brief File search callback
+ * @param[in] path      full path to a resolved file
+ * @param[in] filename  file name
  */
-typedef std::function<void (const std::string&, const char*)> FileReader;
+typedef std::function<void (const std::string& path, const std::string& filename)> FileReader;
 
 /**
- * @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 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 scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
+void scanFilesInDirectory(const std::string& directory, FileReader reader, unsigned int depth);
 
 /**
- * @brief update assembly file info.
+ * @brief copy smack and ownership.
  * @param[in] get path
  * @param[in] set path
  * @param[in] symbolic link
  */
-void updateAssemblyInfo(const std::string& getPath, const std::string& setPath, bool isSymlink = false);
+void copySmackAndOwnership(const std::string& fromPath, const std::string& toPath, bool isSymlink = false);
 
 /**
  * @brief create the new directory.
@@ -218,15 +228,17 @@ bool removeFile(const bf::path& path);
 bool removeAll(const bf::path& path);
 
 /**
- * @brief .deps.json file parser
- * @param[in] package id
- * @param[in] root path
- * @param[in] exec name
- * @param[in] tpa list
- * @param[in] dotnettool
- * @param[in] sqlite3
- * return std::vector<std::string> parser data
- */
-std::vector<std::string> depsJsonParser(std::string pkgId, std::string rootPath, std::string execName, std::string tpaList, bool isTool = false, sqlite3 *tac_db = NULL);
+ * @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);
 
 #endif /* __UTILS_H__ */