*/
ni_error_e createNIDll(const std::string& dllPath, DWORD flags);
-/**
- * @brief create native images for TAC DLLs
- * @param[i] rootPaths paths to TAC directories
- * @param[i] count length of rootPaths
- * @param[i] flags additional flags for the image generator
- */
-void createNIUnderTAC(const std::string rootPaths[], int count, DWORD flags);
-
/**
* @brief creates a symbolic link file, the native image of TAC for specific package.
* @param[i] pkgId package ID
std::string getTizenFXDir();
std::string getTizenFXRefDir();
std::string getExtraDirs();
-
std::string getTPA();
#endif /* __DLL_PATH_MANAGER_H__ */
#include <functional>
-#ifndef DWORD
-#define DWORD uint32_t
-#endif
-
typedef enum {
TAC_ERROR_NONE = 0,
TAC_ERROR_INVALID_PARAMETER = -1,
FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3)
};
-/**
- * @brief an iterator to the begin element in the range that compares equal to option
- * @param[in] begin element
- * @param[in] end elment
- * return return true when elements match
- */
-bool cmdOptionExists(char** begin, char** end, const std::string& option);
-
-/**
- * @brief get current executable path
- * return std::string path
- */
-std::string readSelfPath();
-
/**
* @brief concat path with PATH_SEPARATOR
* @param[in] destination path
* @param[in] original string
* @param[in] pattern to match
* @param[in] replacement string
- * return the modified 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
- * @param[out] root path
+ * return std::string root path
*/
-int getRootPath(const std::string& pkgId, std::string& rootPath);
+std::string getRootPath(const std::string& pkgId);
/**
* @brief get exec name
* @param[in] package id
- * @param[out] exec name
+ * 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
*/
-int getExecName(const std::string& pkgId, std::string& execName);
+std::string getAppType(const std::string& pkgId);
/**
* @brief get metadata value
* @param[in] package id
* @param[in] metadata key
- * @param[out] metadata value
+ * return std::string metadata value
*/
-int getMetadataValue(const std::string& pkgId, const std::string& metadataKey, std::string& metadataValue);
+std::string getMetadataValue(const std::string& pkgId, const std::string& key);
/**
* @brief split path with ":" delimiter and put that in the vector
*/
bool isDirectory(const std::string& path);
-/**
- * @brief get file size
- * @param[in] source path
- * @return size of file
- */
-uintptr_t getFileSize(const std::string& path);
-
/**
* @brief check the file is managed assembly or not.
* @param[in] file path
#endif
#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
-typedef struct Metadata {
- const char *key;
- const char *value;
-} Metadata;
-
bool aotPluginInstalled = false;
extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
}
}
- GList *tag = NULL;
- bool mdValue = false;
- Metadata *mdInfo = NULL;
- tag = g_list_first(list);
- while (tag) {
- mdInfo = (Metadata*)tag->data;
- if (strcmp(mdInfo->key, AOT_METADATA_KEY) == 0 && strcmp(mdInfo->value, METADATA_VALUE) == 0) {
- _DBG("Prefer dotnet application AOT set TRUE");
- mdValue = true;
- }
- tag = g_list_next(tag);
+ std::string metaValue = getMetadataValue(std::string(pkgId), AOT_METADATA_KEY);
+ if (metaValue.empty()) {
+ _ERR("Failed to get metadata from [%s]", pkgId);
+ return 0;
}
- if (mdValue) {
+ if (metaValue == METADATA_VALUE) {
+ _DBG("Prefer dotnet application AOT set TRUE");
+
NICommonOption option = {std::string(), std::string(), std::string()};
if (initNICommon(&option) < 0) {
_ERR("Fail to initialize NI Common");
_INFO("Complete make application to native image");
}
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(std::string(pkgId));
+ if (rootPath.empty()) {
_ERR("Failed to get root path from [%s]", pkgId);
- return 0;
+ return -1;
}
- std::string binDir = concatPath(pkgRoot, "bin");
+ std::string binDir = concatPath(rootPath, "bin");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
if (bf::exists(tacDir)) {
uid_t g_uid = 0;
gid_t g_gid = 0;
if (pkgmgr_installer_info_get_target_uid(&g_uid) < 0) {
_ERR("Failed to get UID");
- return 0;
+ return -1;
}
try {
for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
std::string originPath = bf::read_symlink(symPath).string();
std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
if (!bf::exists(originNIPath)) {
- if(createNIDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) {
+ if (createNIDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) {
_ERR("Failed to create NI file [%s]", originPath.c_str());
return -1;
}
#undef __STR
#undef __XSTR
-typedef struct Metadata {
- const char *key;
- const char *value;
-} Metadata;
-
std::vector<std::string> nugetPackagesAssembliesSha;
std::vector<std::string> tacDB;
std::vector<std::string> createDirectories;
std::vector<std::string> updateTac;
std::string status = "";
-std::string rootPath;
-std::string execName;
-std::string binPath;
static sqlite3 *tac_db = NULL;
bool tacPluginInstalled = false;
bool tacPluginFinished = false;
-bool metadataCheck(GList *list)
-{
- GList *tag = NULL;
- Metadata *mdInfo = NULL;
- tag = g_list_first(list);
- mdInfo = (Metadata*)tag->data;
- if (strcmp(mdInfo->key, TAC_METADATA_KEY) == 0 && strcmp(mdInfo->value, METADATA_VALUE) == 0) {
- _DBG("Prefer nuget cache set TRUE");
- if (initializePluginManager("normal")) {
- _ERR("Fail to initialize PluginManager");
- return false;
- }
- if (initializePathManager(std::string(), std::string(), std::string())) {
- _ERR("Fail to initialize PathManger");
- return false;
- }
- return true;
- }
- return false;
-}
-
-bool appTypeCheck(std::string pkgId)
-{
- uid_t uid = 0;
- if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
- _ERR("Failed to get UID");
- return false;
- }
-
- pkgmgrinfo_pkginfo_h handle;
- int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &handle);
- if (ret != PMINFO_R_OK) {
- _ERR("Failed to get pkg info");
- return false;
- }
-
- bool isDotnetAppType = false;
- auto dotnetAppCounter = [] (pkgmgrinfo_appinfo_h handle, void *userData) -> int {
- char* type = nullptr;
- bool* dotnet = static_cast<bool*>(userData);
- if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) {
- _ERR("Failed to get app type : %s", type);
- return -1;
- }
- if (strcmp(type, "dotnet") == 0) {
- *dotnet = true;
- }
- return 0;
- };
-
- if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, dotnetAppCounter, &isDotnetAppType, uid) != PMINFO_R_OK) {
- _ERR("Failed to get list of app in pkg : %s", pkgId.c_str());
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return false;
- }
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return isDotnetAppType;
-}
-
-void SHA256(std::string path, char outputBuffer[65])
+static void SHA256(std::string path, char outputBuffer[65])
{
FILE *file = fopen(path.c_str(), "rb");
if (!file) {
free(buffer);
}
-void createSHA256Info(std::string sha256Info, std::string nugetPackage)
+static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
{
std::ofstream ofs(sha256Info, std::ios::app);
int assembly_count = 0;
ofs.close();
}
-int compareSHA256Info(std::string sha256Info, std::string nugetPackage)
+static int compareSHA256Info(std::string sha256Info, std::string nugetPackage)
{
int compare_count = 0;
int assembly_count = 0;
return 0;
}
-int copyNCreateSymlink(std::string tacVersionDir, std::string nugetPackage, bool isCreateTacDir)
+static int copyNCreateSymlink(std::string binPath, std::string tacVersionDir, std::string nugetPackage, bool isCreateTacDir)
{
uid_t g_uid = 0;
gid_t g_gid = 0;
return 0;
}
-void depsJsonCheck() {
+static void depsJsonCheck(std::string rootPath, std::string binPath, std::string execName)
+{
for (auto& npAssembly : depsJsonParser(rootPath, execName, getTPA())) {
std::string nuget_package = npAssembly.substr(0, npAssembly.rfind(':'));
std::string assembly_name = npAssembly.substr(npAssembly.rfind(':') + 1);
}
tacPluginInstalled = true;
- if (!appTypeCheck(std::string(pkgId))) {
- _INFO("App type is not dotnet");
+ if (initializePathManager(std::string(), std::string(), std::string())) {
+ _ERR("Fail to initialize PathManger");
+ return 0;
+ }
+
+ std::string appType = getAppType(std::string(pkgId));
+ if (strstr(appType.c_str(), "dotnet") == NULL) {
+ _ERR("App type is not dotnet");
return 0;
}
- if (getExecName(std::string(pkgId), execName) < 0) {
+ std::string execName = getExecName(std::string(pkgId));
+ std::string rootPath = getRootPath(std::string(pkgId));
+ if (execName.empty() || rootPath.empty()) {
return 0;
}
- if (getRootPath(std::string(pkgId), rootPath) < 0) {
+ std::string binPath = concatPath(rootPath, "bin");
+ std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
+ if (metaValue.empty()) {
return 0;
- } else {
- binPath = concatPath(rootPath, "bin");
}
- if (metadataCheck(list)) {
- depsJsonCheck();
+ if (metaValue == METADATA_VALUE) {
+ depsJsonCheck(rootPath, binPath, execName);
}
status = "install";
return -1;
}
- if (copyNCreateSymlink(tac_version_dir, np, true) < 0) {
+ if (copyNCreateSymlink(binPath, tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
_INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
if (!bf::is_symlink(sha256_info)) {
if (compareSHA256Info(sha256_info, np)) {
- if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
+ if (copyNCreateSymlink(binPath, tac_version_dir, np, false) < 0) {
_ERR("Failed to create symlink");
return -1;
}
}
}
if (!bf::exists(sha256_info)) {
- if(!removeAll(tac_version_dir)) {
+ if (!removeAll(tac_version_dir)) {
_ERR("Failed to remove of %s", tac_version_dir.c_str());
}
}
return 0;
}
-static int sqliteCb(void *count, int argc, char **argv, char **colName) {
+static int sqliteCb(void *count, int argc, char **argv, char **colName)
+{
int *c = (int*)count;
*c = atoi(argv[0]);
return 0;
}
-int updateTacDB(sqlite3 *sqlite)
+static int updateTacDB(sqlite3 *sqlite)
{
for (auto& unp : updateTac) {
int count = -1;
}
tacPluginInstalled = true;
- if (!appTypeCheck(std::string(pkgId))) {
- _INFO("App type is not dotnet");
+ if (initializePathManager(std::string(), std::string(), std::string())) {
+ _ERR("Fail to initialize PathManger");
return 0;
}
- if (getExecName(std::string(pkgId), execName) < 0) {
+
+ std::string appType = getAppType(std::string(pkgId));
+ if (strstr(appType.c_str(), "dotnet") == NULL) {
+ _ERR("App type is not dotnet");
return 0;
}
- if (getRootPath(std::string(pkgId), rootPath) < 0) {
+ std::string execName = getExecName(std::string(pkgId));
+ std::string rootPath = getRootPath(std::string(pkgId));
+ if (execName.empty() || rootPath.empty()) {
return 0;
- } else {
- binPath = concatPath(rootPath, "bin");
}
+ std::string binPath = concatPath(rootPath, "bin");
+
if (!strcmp("removed", status.c_str())) {
_INFO("Skipped to parse of deps.json");
} else {
- if (metadataCheck(list)) {
- depsJsonCheck();
+ std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
+ if (metaValue.empty()) {
+ return 0;
+ }
+ if (metaValue == METADATA_VALUE) {
+ depsJsonCheck(rootPath, binPath, execName);
}
}
return -1;
}
- if (copyNCreateSymlink(tac_version_dir, np, true) < 0) {
+ if (copyNCreateSymlink(binPath, tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
_INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
if (!bf::is_symlink(sha256_info)) {
if (compareSHA256Info(sha256_info, np)) {
- if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
+ if (copyNCreateSymlink(binPath, tac_version_dir, np, false) < 0) {
_ERR("Failed to create symlink");
return -1;
}
}
}
if (!bf::exists(sha256_info)) {
- if(!removeAll(tac_version_dir)) {
+ if (!removeAll(tac_version_dir)) {
_ERR("Failed to remove of %s", tac_version_dir.c_str());
}
}
int main(int argc, char *argv[])
{
_INFO("##### Run in standalone mode #####");
-
+
char* standalonePath = nullptr;
bool paddingExist = false;
const char* appRootPath = NULL;
return 0;
}
-
return realMain(argc, argv, "candidate");
}
-
free(lang);
}
+static std::string readSelfPath()
+{
+ char buff[PATH_MAX];
+ ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
+ if (len != -1) {
+ buff[len] = '\0';
+ return std::string(buff);
+ }
+
+ return "";
+}
+
void CoreRuntime::preload()
{
typedef void (*PreloadDelegate)();
}
#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
+static uintptr_t getFileSize(const std::string& path)
+{
+ struct stat sb;
+
+ if (stat(path.c_str(), &sb) == 0) {
+ return sb.st_size;
+ }
+
+ return 0;
+}
+
// Get next base address to be used for system ni image from file
// __SYSTEM_BASE_FILE should be checked for existance before calling this function
static uintptr_t getNextBaseAddrFromFile()
}
// Save base address of system ni image to file
-static void updateBaseAddrFile(const std::string &absNIPath, uintptr_t baseAddr)
+static void updateBaseAddrFile(const std::string& absNIPath, uintptr_t baseAddr)
{
uintptr_t niSize = getFileSize(absNIPath);
if (niSize == 0) {
}
// check if dll is listed in TPA
-static bool isTPADll(const std::string &dllPath)
+static bool isTPADll(const std::string& dllPath)
{
std::string absDllPath = getAbsolutePath(dllPath);
if (createTACPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to generate symbolic link file [%s]\n", pkgId);
return -1;
- }else {
+ } else {
fprintf(stdout, "Complete make symbolic link file to tac\n");
}
__tpa.clear();
}
-
ni_error_e createNIPlatform(DWORD flags)
{
if (createCoreLibNI(flags) != NI_ERROR_NONE) {
return crossgen(dllPath, std::string(), flags);
}
-void createNIUnderTAC(std::vector<std::string> nugets, DWORD flags)
+static void createNIUnderTAC(const std::vector<std::string>& nugets, DWORD flags)
{
std::string appPaths;
for (auto& nuget : nugets) {
return NI_ERROR_CORE_NI_FILE;
}
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
std::string paths = binDir + ":" + libDir + ":" + tacDir;
std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
if (!bf::exists(originNIPath)) {
flags |= NI_FLAGS_APPNI;
- if(crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
+ if (crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
return NI_ERROR_UNKNOWN;
}
ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string paths[] = {binDir, libDir, tacDir};
return NI_ERROR_CORE_NI_FILE;
}
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
std::string paths = binDir + ":" + libDir + ":" + tacDir;
std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
if (!bf::exists(originNIPath)) {
flags |= NI_FLAGS_APPNI;
- if(crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
+ if (crossgen(originPath, paths, flags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
return NI_ERROR_UNKNOWN;
}
ni_error_e removeNIUnderPkgRoot(const std::string& pkgId)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string libDir = concatPath(pkgRoot, "lib");
+ std::string binDir = concatPath(rootPath, "bin");
+ std::string libDir = concatPath(rootPath, "lib");
std::string paths[] = {binDir, libDir};
removeNIUnderDirs(paths, 2);
return list;
}
+static bool cmdOptionExists(char** begin, char** end, const std::string& option)
+{
+ return std::find(begin, end, option) != end;
+}
+
static void help(const char *argv0)
{
const char* helpDesc =
tac_error_e resetTACPackage(const std::string& pkgId)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return TAC_ERROR_INVALID_PACKAGE;
}
std::vector<std::string> tacNativeImage;
- std::string binDir = concatPath(pkgRoot, "bin");
+ std::string binDir = concatPath(rootPath, "bin");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
if (bf::exists(tacDir)) {
try {
tac_error_e disableTACPackage(const std::string& pkgId)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return TAC_ERROR_INVALID_PACKAGE;
}
- std::string binDir = concatPath(pkgRoot, "bin");
+ std::string binDir = concatPath(rootPath, "bin");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
if (bf::exists(tacDir)) {
tac_error_e enableTACPackage(const std::string& pkgId)
{
- std::string rootPath;
- if (getRootPath(pkgId, rootPath) < 0) {
+ std::string rootPath = getRootPath(pkgId);
+ if (rootPath.empty()) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
return TAC_ERROR_INVALID_PACKAGE;
}
- std::string execName;
- if (getExecName(pkgId, execName) < 0) {
- fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
+ std::string execName = getExecName(pkgId);
+ if (execName.empty()) {
+ fprintf(stderr, "Failed to get exec name from [%s]\n", pkgId.c_str());
return TAC_ERROR_INVALID_PACKAGE;
}
- std::string metaValue;
- if (getMetadataValue(pkgId, TAC_METADATA_KEY, metaValue) < 0) {
- fprintf(stderr, "Failed to get root path from [%s]\n", pkgId.c_str());
+ std::string metaValue = getMetadataValue(pkgId, TAC_METADATA_KEY);
+ if (metaValue.empty()) {
+ fprintf(stderr, "Failed to get metadata from [%s]\n", pkgId.c_str());
return TAC_ERROR_INVALID_PACKAGE;
}
bool* is_db_corrupted = static_cast<bool*>(user_data);
std::string result_DB_check = argv[0];
std::transform(result_DB_check.begin(), result_DB_check.end(), result_DB_check.begin(), ::tolower);
- if(result_DB_check != "ok") {
+ if (result_DB_check != "ok") {
*is_db_corrupted = true;
_ERR("DB integrity check failed");
return -1;
// if LogManager is not initialized, it will return 0;
int redirectFD()
{
- if (!__isInit) return 0;
+ if (!__isInit)
+ return 0;
if (__pfd[1] < 0) {
_ERR("fail to create pipe for logging");
if (plugin_tpa_list) {
_INFO("plugin TPA list found. use TPA list for plugin");
plugin_tpa = plugin_tpa_list;
- } else if (!__dllPath->extra_dirs.empty()){
+ } else if (!__dllPath->extra_dirs.empty()) {
_INFO("plugin extra directory found. use plugin extra directroy for TPA");
addAssembliesFromDirectories(__dllPath->extra_dirs, plugin_tpa);
}
return getPlatformTPA() + ":" + getPluginTPA();
}
-
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include <dlfcn.h>
#include "plugin_manager.h"
__pluginFunc->finalize();
}
}
-
return iCompare(fileName, fileName.size()-7, ".ni", 0, 3);
}
-bool cmdOptionExists(char** begin, char** end, const std::string& option)
-{
- return std::find(begin, end, option) != end;
-}
-
-std::string readSelfPath()
-{
- char buff[PATH_MAX];
- ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
- if (len != -1) {
- buff[len] = '\0';
- return std::string(buff);
- }
-
- return "";
-}
-
std::string concatPath(const std::string& path1, const std::string& path2)
{
std::string path(path1);
return absPath;
}
-int getRootPath(const std::string& pkgId, std::string& rootPath)
+std::string getRootPath(const std::string& pkgId)
{
int ret = 0;
char *path = 0;
uid_t uid = 0;
+ std::string rootPath;
if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
_ERR("Failed to get UID");
- return -1;
+ return rootPath;
}
pkgmgrinfo_pkginfo_h handle;
if (uid == 0) {
ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &handle);
if (ret != PMINFO_R_OK) {
- return -1;
+ return rootPath;
}
} else {
ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &handle);
if (ret != PMINFO_R_OK) {
- return -1;
+ return rootPath;
}
}
ret = pkgmgrinfo_pkginfo_get_root_path(handle, &path);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return -1;
+ return rootPath;
}
rootPath = path;
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return 0;
+
+ return rootPath;
}
-int getExecName(const std::string& pkgId, std::string& execName)
+std::string getExecName(const std::string& pkgId)
{
char *exec = NULL;
char *appId = 0;
+ std::string execName;
pkgmgrinfo_pkginfo_h pkg_handle;
int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &pkg_handle);
if (ret != PMINFO_R_OK) {
- return -1;
+ return execName;
}
ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return -1;
+ return execName;
}
pkgmgrinfo_appinfo_h app_handle;
ret = pkgmgrinfo_appinfo_get_appinfo(appId, &app_handle);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return -1;
+ return execName;
}
ret = pkgmgrinfo_appinfo_get_exec(app_handle, &exec);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return -1;
+ return execName;
}
execName = std::string(exec).substr(std::string(exec).rfind('/') + 1);
pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return 0;
+
+ return execName;
}
-int getMetadataValue(const std::string& pkgId, const std::string& metadataKey, std::string& metadataValue)
+std::string getAppType(const std::string& pkgId)
+{
+ char *appId = 0;
+ char *type = 0;
+ std::string appType;
+
+ pkgmgrinfo_pkginfo_h pkg_handle;
+ int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &pkg_handle);
+ if (ret != PMINFO_R_OK) {
+ return appType;
+ }
+ ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+ return appType;
+ }
+
+ pkgmgrinfo_appinfo_h app_handle;
+ ret = pkgmgrinfo_appinfo_get_appinfo(appId, &app_handle);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+ return appType;
+ }
+ ret = pkgmgrinfo_appinfo_get_apptype(app_handle, &type);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+ return appType;
+ }
+ appType = type;
+
+ pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+
+ return appType;
+}
+
+std::string getMetadataValue(const std::string& pkgId, const std::string& key)
{
char *value = NULL;
char *appId = 0;
+ std::string metadataValue;
pkgmgrinfo_pkginfo_h pkg_handle;
int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &pkg_handle);
if (ret != PMINFO_R_OK) {
- return -1;
+ return metadataValue;
}
ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return -1;
+ return metadataValue;
}
pkgmgrinfo_appinfo_h app_handle;
ret = pkgmgrinfo_appinfo_get_appinfo(appId, &app_handle);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return -1;
+ return metadataValue;
}
- ret = pkgmgrinfo_appinfo_get_metadata_value(app_handle, metadataKey.c_str(), &value);
+ ret = pkgmgrinfo_appinfo_get_metadata_value(app_handle, key.c_str(), &value);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- //Does not return error because the metadata key may not exist.
- return 0;
+ return metadataValue;
}
metadataValue = std::string(value);
pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- return 0;
+
+ return metadataValue;
}
std::string getBaseName(const std::string& path)
struct stat sb;
if (stat(path.c_str(), &sb) != 0) {
return false;
- } else if (sb.st_mode & S_IFDIR) {
+ }
+ if (sb.st_mode & S_IFDIR) {
return true;
} else {
return false;
}
}
-uintptr_t getFileSize(const std::string& path)
-{
- struct stat sb;
-
- if (stat(path.c_str(), &sb) == 0) {
- return sb.st_size;
- }
-
- return 0;
-}
-
std::string getAssemblyNameFromPath(const std::string& path)
{
std::string ret(getFileName(path));
return ret;
}
-void addAssembliesFromDirectories(const std::vector<std::string>& directories, std::string& list) {
+void addAssembliesFromDirectories(const std::vector<std::string>& directories, std::string& list)
+{
std::vector<std::string> assems;
std::unordered_map<std::string, std::string> assemPaths;
}
}
-static bool setOwnership(const bf::path& path, uid_t uid, gid_t gid) {
+static bool setOwnership(const bf::path& path, uid_t uid, gid_t gid)
+{
int fd = open(path.c_str(), O_RDONLY);
if (fd < 0) {
_ERR("Can't open directory: %s", path.c_str());
return true;
}
-static bool setDirPermissions(const bf::path& path, bf::perms permissions) {
+static bool setDirPermissions(const bf::path& path, bf::perms permissions)
+{
bs::error_code error;
bf::permissions(path, permissions, error);
if (error) {
return true;
}
-static bool setDirOwnershipAndPermissions(const bf::path& path, bf::perms permissions, uid_t uid, gid_t gid) {
+static bool setDirOwnershipAndPermissions(const bf::path& path, bf::perms permissions, uid_t uid, gid_t gid)
+{
if (!setOwnership(path, uid, gid)) {
_ERR("Failed to change owner: %s, (uid: %d, gid: %d)", path.c_str(), uid, gid);
return false;
return true;
}
-static bool copyOwnershipAndPermissions(const bf::path& path, const bf::path& path2) {
+static bool copyOwnershipAndPermissions(const bf::path& path, const bf::path& path2)
+{
if (!bf::exists(path)) {
_ERR("Failed to copy ownership and permissions from %s to %s", path.c_str(), path2.c_str());
return false;
return true;
}
-bool createDir(const bf::path& path) {
+bool createDir(const bf::path& path)
+{
if (bf::exists(path)) {
return true;
}
return true;
}
-bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags) {
+bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags)
+{
try {
// Check whether the function call is valid
if (!bf::exists(path1) || !bf::is_directory(path1)) {
return true;
}
-bool copyFile(const bf::path& path1, const bf::path& path2) {
+bool copyFile(const bf::path& path1, const bf::path& path2)
+{
bs::error_code error;
if (!bf::exists(path1)) {
return false;
return true;
}
-bool moveFile(const bf::path& path1, const bf::path& path2) {
+bool moveFile(const bf::path& path1, const bf::path& path2)
+{
if (!bf::exists(path1) || bf::exists(path2)) {
return false;
}
return true;
}
-bool removeFile(const bf::path& path) {
+bool removeFile(const bf::path& path)
+{
if (!bf::exists(path)) {
return true;
}
return true;
}
-bool removeAll(const bf::path& path) {
+bool removeAll(const bf::path& path)
+{
if (!exists(path)) {
return true;
}