Add define for TAC in launcher_env.h
authorj-h.choi <j-h.choi@samsung.com>
Thu, 27 Jun 2019 06:12:06 +0000 (15:12 +0900)
committerj-h.choi <j-h.choi@samsung.com>
Wed, 3 Jul 2019 04:51:24 +0000 (13:51 +0900)
NativeLauncher/inc/launcher_env.h
NativeLauncher/inc/utils.h
NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc
NativeLauncher/installer-plugin/ui-application.cc
NativeLauncher/launcher/dotnet/dotnet_launcher.cc
NativeLauncher/tool/ni_common.cc
NativeLauncher/tool/tactool.cc
NativeLauncher/util/db_manager.cc
NativeLauncher/util/utils.cc
packaging/dotnet-launcher.spec

index 55f600d..dca5a30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #ifndef __LAUNCHER_ENV_H_
 #define __LAUNCHER_ENV_H_
 
-#define PLUGIN_PATH         "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
-#define ENV_FILE_PATH       "/usr/share/dotnet.tizen/lib/coreclr_env.list"
-#define AOT_METADATA_KEY    "http://tizen.org/metadata/prefer_dotnet_aot"
-#define AOT_METADATA_VALUE  "true"
-#define APP_NI_SUB_DIR      "/.native_image"
+#define PLUGIN_PATH                  "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
+#define ENV_FILE_PATH                "/usr/share/dotnet.tizen/lib/coreclr_env.list"
+#define AOT_METADATA_KEY             "http://tizen.org/metadata/prefer_dotnet_aot"
+#define TAC_METADATA_KEY             "http://tizen.org/metadata/prefer_nuget_cache"
+#define METADATA_VALUE               "true"
+#define APP_NI_SUB_DIR               ".native_image"
+#define TAC_SYMLINK_SUB_DIR          ".tac_symlink"
+#define TAC_SHA_256_INFO             ".SHA256.info"
+#define TAC_APP_LIST_DB              "/opt/usr/dotnet/.TAC.App.list.db"
+#define TAC_APP_LIST_RESTORE_DB      "/opt/usr/dotnet/.TAC.App.list.restore.db"
+#define TIZEN_DOTNET_NUGET           "Tizen.NET"
+#define TIZEN_DOTNET_SDK_NUGET       "Tizen.NET.Sdk"
+#define NET_STANDARD_LIBRARY_NUGET   "NETStandard.Library"
 
 #endif //__LAUNCHER_ENV_H_
\ No newline at end of file
index bb72e00..f1d4306 100644 (file)
@@ -133,6 +133,13 @@ void scanFilesInDir(const std::string& directory, FileReader reader, unsigned in
 bool createDir(const bf::path& path);
 
 /**
+ * @brief update assembly file info.
+ * @param[in] get path
+ * @param[in] set path
+ */
+void updateAssemblyInfo(const std::string& getPath, const std::string& setPath);
+
+/**
  * @brief copy the directory.
  * @param[in] path to the source directory
  * @param[in] path to the target directory
index ffed938..0ba9d90 100644 (file)
 #include "log.h"
 #include "utils.h"
 
-#ifdef  LOG_TAG
-#undef  LOG_TAG
-#endif
-#define LOG_TAG "NETCORE_INSTALLER_PLUGIN"
-
 #include <cstring>
 #include <vector>
 #include <sstream>
 #include <glib.h>
+#include <pkgmgr_installer_info.h>
+
+#ifdef  LOG_TAG
+#undef  LOG_TAG
+#endif
+#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
 
 typedef struct Metadata {
        const char *key;
@@ -41,7 +42,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
        tag = g_list_first(list);
        while (tag) {
                mdInfo = (Metadata*)tag->data;
-               if (strcmp(mdInfo->key, AOT_METADATA_KEY) == 0 && strcmp(mdInfo->value, AOT_METADATA_VALUE) == 0) {
+               if (strcmp(mdInfo->key, AOT_METADATA_KEY) == 0 && strcmp(mdInfo->value, METADATA_VALUE) == 0) {
                        _DBG("Prefer dotnet application AOT set TRUE");
                        mdValue = true;
                }
@@ -61,6 +62,44 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                } else {
                        _INFO("Complete make application to native image");
                }
+
+               std::string pkgRoot;
+               if (getRootPath(pkgId, pkgRoot) < 0) {
+                       fprintf(stderr, "Failed to get root path from [%s]\n", pkgId);
+                       return -1;
+               }
+
+               std::string binDir = concatPath(pkgRoot, "bin");
+               std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
+               if (bf::exists(tacDir)) {
+                       uid_t uid = 0;
+                       if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
+                               _ERR("Failed to get UID");
+                               return -1;
+                       }
+                       for (auto& symlinkAssembly : bf::recursive_directory_iterator(bf::path(tacDir))) {
+                               std::string symPath = symlinkAssembly.path().string();
+                               if (!isNativeImage(symPath)) {
+                                       std::string originPath = bf::read_symlink(symPath).string();
+                                       std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
+                                       if (!bf::exists(originNiPath)) {
+                                               if(createNiDll(originPath, false) != NI_ERROR_NONE) {
+                                                       _ERR("Failed to create NI file [%s]\n", originPath.c_str());
+                                                       return -1;
+                                               }
+                                       }
+                                       std::string setNiPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
+                                       if (!bf::exists(setNiPath)) {
+                                               bf::create_symlink(originNiPath, setNiPath);
+                                               fprintf(stderr, "%s symbolic link file generated successfully.\n", setNiPath.c_str());
+                                               if (lchown(setNiPath.c_str(), uid, 0)) {
+                                                       _ERR("Failed to change owner of: %s", setNiPath.c_str());
+                                                       return -1;
+                                               }
+                                       }
+                               }
+                       }
+               }
        }
        return 0;
 }
index 64afc73..c5d6a2f 100644 (file)
 #include "utils.h"
 #include "db_manager.h"
 
-#ifdef  LOG_TAG
-#undef  LOG_TAG
-#endif
-#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
-
 #include <cstring>
 #include <fstream>
 #include <sstream>
 #include <pkgmgr_installer_info.h>
 #include <openssl/sha.h>
 
+#ifdef  LOG_TAG
+#undef  LOG_TAG
+#endif
+#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
+
+#define __XSTR(x) #x
+#define __STR(x) __XSTR(x)
+static const char* __TAC_DIR = __STR(TAC_DIR);
+#undef __STR
+#undef __XSTR
+
 typedef struct Metadata {
        const char *key;
        const char *value;
 } Metadata;
 
-const std::string mOptUsrDotnet = "/opt/usr/dotnet";
-const std::string mTizenNET = "Tizen.NET";
-const std::string mTizenNETSdk = "Tizen.NET.Sdk";
-const std::string mNETStandardLibrary = "NETStandard.Library";
-const std::string mTacRelease = ".TAC.Release";
-const std::string mDepsJson = ".deps.json";
-const std::string mBackup = ".bck";
-const std::string mdValue = "true";
-const std::string mdKey = "http://tizen.org/metadata/prefer_nuget_cache";
-const std::string tacAppListDB = mOptUsrDotnet + "/.TAC.App.list.db";
-
 std::vector<std::string> nugetPackagesAssembliesShaR2R;
 std::vector<std::string> tacDB;
 std::vector<std::string> createDirectories;
@@ -58,7 +53,7 @@ std::vector<std::string> updateTac;
 std::string status = "";
 std::string rootPath;
 std::string execName;
-bf::path binPath;
+std::string binPath;
 bool isCreateDirectory = false;
 static sqlite3 *tac_db = NULL;
 
@@ -68,11 +63,16 @@ int metadataCheck(GList *list)
        Metadata *mdInfo = NULL;
        tag = g_list_first(list);
        mdInfo = (Metadata*)tag->data;
-       if (mdInfo->key == mdKey && mdInfo->value == mdValue) {
+       if (strcmp(mdInfo->key, TAC_METADATA_KEY) == 0 && strcmp(mdInfo->value, METADATA_VALUE) == 0) {
                _DBG("Prefer nuget cache set TRUE");
+               NiCommonOption option = {std::string(), std::string(), std::string()};
+               if (initNICommon(&option) < 0) {
+                       _ERR("Fail to initialize NI Common");
+                       return -1;
+               }
                return 0;
        } else {
-               return 1;
+               return -1;
        }
 }
 
@@ -182,9 +182,9 @@ int SHA256(std::string path, char outputBuffer[65])
 
 int depsJsonParser()
 {
-       std::string deps_json_name = execName.substr(0, execName.rfind(".dll")) + mDepsJson;
-       if (bf::exists(rootPath + "/" + deps_json_name)) {
-               std::string deps_json_path = rootPath + "/" + deps_json_name;
+       std::string deps_json_name = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
+       if (bf::exists(concatPath(rootPath, deps_json_name))) {
+               std::string deps_json_path = concatPath(rootPath, deps_json_name);
                std::ifstream ifs(deps_json_path);
                Json::CharReaderBuilder reader;
                Json::Value root;
@@ -199,8 +199,8 @@ int depsJsonParser()
                        std::string runtimeTarget_name = runtimeTargetName.asString();
                        const Json::Value nugetPackages = root["targets"][runtimeTarget_name.c_str()];
                        for (auto& nuget : nugetPackages.getMemberNames()) {
-                               if (strstr(nuget.c_str(), mTizenNET.c_str()) != NULL ||
-                                       strstr(nuget.c_str(), mTizenNETSdk.c_str()) != NULL ||
+                               if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) != NULL ||
+                                       strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) != NULL ||
                                        strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL ||
                                        strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) {
                                        continue;
@@ -210,20 +210,20 @@ int depsJsonParser()
                                                const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
                                                std::string r2r = "";
                                                for (auto& dependency : dependencies.getMemberNames()) {
-                                                       if (strstr(dependency.c_str(), mTizenNET.c_str()) != NULL ||
-                                                               strstr(dependency.c_str(), mNETStandardLibrary.c_str()) != NULL) {
+                                                       if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) != NULL ||
+                                                               strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) != NULL) {
                                                                continue;
                                                        } else {
                                                                r2r = "--r2r";
                                                        }
                                                }
-                                               if (strcmp(r2r.c_str(), "--r2r")) {
+                                               if (strcmp(r2r.c_str(), "--r2r") != 0) {
                                                        tacDB.push_back(nuget);
                                                        _INFO("Nuget package : %s", nuget.c_str());
                                                        for (auto& assembly : assemblies.getMemberNames()) {
                                                                std::string assembly_name = assembly.substr(assembly.rfind('/') + 1);
                                                                char buffer[65];
-                                                               SHA256((binPath / assembly_name).string(), buffer);
+                                                               SHA256(concatPath(binPath, assembly_name), buffer);
                                                                nugetPackagesAssembliesShaR2R.push_back(nuget + "/" + assembly_name + "/" + buffer + "/" + r2r);
                                                                _INFO("Assembly / SHA256 : %s / %s", assembly_name.c_str(), buffer);
                                                        }
@@ -248,20 +248,10 @@ int createSymlink(bf::path tac_version_dir, std::string np)
                std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind('/'));
                std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind('/') + 1);
                std::string r2r = npAssemblyShaR2R.substr(npAssemblyShaR2R.rfind('/') + 1);
-               std::string ni_assembly = assembly.substr(0, assembly.rfind(".dll")) + ".ni.dll";
                if (!strcmp(nuget_package.c_str(), np.c_str())) {
-                       if (bf::exists(binPath / assembly)) {
+                       if (bf::exists(concatPath(binPath, assembly))) {
                                if (isCreateDirectory) {
-                                       std::string command = "nitool --dll " + binPath.string() + "/" + assembly + " " + r2r;
-                                       if (system(command.c_str()) != 0) {
-                                               _ERR("Failed to create ni dll [%s]", command.c_str());
-                                               return -1;
-                                       }
-                                       if (!copyFile(binPath / ni_assembly, tac_version_dir / ni_assembly)) {
-                                               _ERR("Failed to move of %s", ni_assembly.c_str());
-                                               return -1;
-                                       }
-                                       if (!copyFile(binPath / assembly, tac_version_dir / assembly)) {
+                                       if (!copyFile(concatPath(binPath, assembly), tac_version_dir / assembly)) {
                                                _ERR("Failed to move of %s", assembly.c_str());
                                                return -1;
                                        }
@@ -270,22 +260,14 @@ int createSymlink(bf::path tac_version_dir, std::string np)
                                        _ERR("Failed to get UID");
                                        return -1;
                                }
-                               bf::create_symlink(tac_version_dir / ni_assembly, binPath / mTacRelease / ni_assembly, error);
-                               if (error) {
-                                       _ERR("Failed to create symlink");
-                                       return -1;
-                               }
-                               bf::create_symlink(tac_version_dir / assembly, binPath / mTacRelease / assembly, error);
+                               std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
+                               bf::create_symlink(tac_version_dir / assembly, concatPath(tac_dir, assembly), error);
                                if (error) {
                                        _ERR("Failed to create symlink");
                                        return -1;
                                }
-                               if (lchown((binPath / mTacRelease / ni_assembly).c_str(), uid, 0)) {
-                                       _ERR("Failed to change owner of: %s", (binPath / mTacRelease / ni_assembly).c_str());
-                                       return -1;
-                               }
-                               if (lchown((binPath / mTacRelease / assembly).c_str(), uid, 0)) {
-                                       _ERR("Failed to change owner of: %s", (binPath / mTacRelease / assembly).c_str());
+                               if (lchown(concatPath(tac_dir, assembly).c_str(), uid, 0)) {
+                                       _ERR("Failed to change owner of: %s", concatPath(tac_dir, assembly).c_str());
                                        return -1;
                                }
                        }
@@ -302,19 +284,12 @@ int removeOriginalAssembly() {
                std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind('/'));
                std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind('/') + 1);
                std::string r2r = npAssemblyShaR2R.substr(npAssemblyShaR2R.rfind('/') + 1);
-               std::string ni_assembly = assembly.substr(0, assembly.rfind(".dll")) + ".ni.dll";
-               if (bf::exists(binPath / assembly)) {
-                       if (!removeFile(binPath / assembly)) {
+               if (bf::exists(concatPath(binPath, assembly))) {
+                       if (!removeFile(concatPath(binPath, assembly))) {
                                _ERR("Failed to remove of %s", assembly.c_str());
                                return -1;
                        }
                }
-               if (bf::exists(binPath / ni_assembly)) {
-                       if (!removeFile(binPath / ni_assembly)) {
-                               _ERR("Failed to remove of %s", ni_assembly.c_str());
-                               return -1;
-                       }
-               }
        }
        return 0;
 }
@@ -334,7 +309,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
        if (getRootPath(std::string(pkgId), rootPath) < 0) {
                return 0;
        } else {
-               binPath = rootPath / bf::path("bin");
+               binPath = concatPath(rootPath, "bin");
        }
        if (!metadataCheck(list)) {
                if (depsJsonParser()) {
@@ -343,9 +318,9 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
        }
 
        status = "install";
-       tac_db = dbCreate(tacAppListDB);
+       tac_db = dbCreate(TAC_APP_LIST_DB);
        if (tac_db) {
-               if (!dbOpen(tac_db, tacAppListDB)) {
+               if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
                        return 0;
                }
        } else {
@@ -357,9 +332,10 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                _ERR("Not exist .deps.json file");
                return 0;
        }
-       if (!bf::exists(binPath / mTacRelease)) {
-               if (!createDir(binPath / mTacRelease)) {
-                       _INFO("Cannot create directory: %s", (binPath / mTacRelease).c_str());
+       std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
+       if (!bf::exists(tac_dir)) {
+               if (!createDir(tac_dir)) {
+                       _INFO("Cannot create directory: %s", tac_dir.c_str());
                        return 0;
                }
        }
@@ -370,7 +346,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                _INFO("TAC name : %s", tac_name.c_str());
                _INFO("TAC version : %s", tac_version.c_str());
 
-               bf::path tac_version_dir = bf::path(mOptUsrDotnet) / np;
+               bf::path tac_version_dir = concatPath(__TAC_DIR, np);
                isCreateDirectory = false;
                if (!bf::exists(tac_version_dir)) {
                        _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
@@ -380,7 +356,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                        }
                        isCreateDirectory = true;
                        createDirectories.push_back(tac_version_dir.string());
-                       std::string sha256_info = (tac_version_dir / bf::path("SHA256.info")).string();
+                       std::string sha256_info = (tac_version_dir / TAC_SHA_256_INFO).string();
                        std::ofstream ofs(sha256_info, std::ios::app);
                        int assembly_count = 0;
                        for (auto& npAssemblyShaR2R : nugetPackagesAssembliesShaR2R) {
@@ -404,7 +380,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                        }
                        std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
                                        "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
-                       dbInsert(tac_db, tacAppListDB, sql);
+                       dbInsert(tac_db, TAC_APP_LIST_DB, sql);
                } else {
                        _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
                        int compare_count = 0;
@@ -419,7 +395,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                                std::string r2r = npAssemblyShaR2R.substr(npAssemblyShaR2R.rfind('/') + 1);
                                if (!strcmp(nuget_package.c_str(), np.c_str())) {
                                        assembly_count++;
-                                       std::string sha256_info = (tac_version_dir / bf::path("SHA256.info")).string();
+                                       std::string sha256_info = (tac_version_dir / TAC_SHA_256_INFO).string();
                                        std::ifstream ifs(sha256_info);
                                        std::string get_str;
                                        if (ifs.is_open()) {
@@ -441,7 +417,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                                }
                                std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
                                                "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
-                               dbInsert(tac_db, tacAppListDB, sql);
+                               dbInsert(tac_db, TAC_APP_LIST_DB, sql);
                        } else {
                                _INFO("Different : %s", tac_name.c_str());
                        }
@@ -466,7 +442,7 @@ int updateTacDB(const char *pkgId)
                int ret;
                int count = 0;
                if (tac_db) {
-                       if (!dbOpen(tac_db, tacAppListDB)) {
+                       if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
                                return 0;
                        }
                } else {
@@ -480,8 +456,8 @@ int updateTacDB(const char *pkgId)
                        sqlite3_free(error);
                }
                if (count < 1) {
-                       bf::path tac_version_dir_prev = bf::path(mOptUsrDotnet) / unp;
-                       bf::path tac_version_dir_backup = bf::path(mOptUsrDotnet) / (unp + mBackup);
+                       bf::path tac_version_dir_prev = concatPath(__TAC_DIR, unp);
+                       bf::path tac_version_dir_backup = concatPath(__TAC_DIR, unp) + ".bck";
                        if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
                                _ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
                                return -1;
@@ -510,7 +486,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
        if (getRootPath(std::string(pkgId), rootPath) < 0) {
                return 0;
        } else {
-               binPath = rootPath / bf::path("bin");
+               binPath = concatPath(rootPath, "bin");
        }
        if (!strcmp("removed", status.c_str())) {
                _INFO("Skipped to parse of deps.json");
@@ -523,9 +499,9 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
        }
 
        status = "update";
-       tac_db = dbCreate(tacAppListDB);
+       tac_db = dbCreate(TAC_APP_LIST_DB);
        if (tac_db) {
-               if (!dbOpen(tac_db, tacAppListDB)) {
+               if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
                        return 0;
                }
        } else {
@@ -534,18 +510,19 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
        }
 
        std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
-       updateTac = dbSelect(tac_db, tacAppListDB, sql);
+       updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
 
        if (tacDB.empty()) {
                sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
-               dbDelete(tac_db, tacAppListDB, sql);
+               dbDelete(tac_db, TAC_APP_LIST_DB, sql);
                if (updateTacDB(pkgId)) {
                        return 0;
                }
        } else {
-               if (!bf::exists(binPath / mTacRelease)) {
-                       if (!createDir(binPath / mTacRelease)) {
-                               _INFO("Cannot create directory: %s", (binPath / mTacRelease).c_str());
+               std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
+               if (!bf::exists(tac_dir)) {
+                       if (!createDir(tac_dir)) {
+                               _INFO("Cannot create directory: %s", tac_dir.c_str());
                                return 0;
                        }
                }
@@ -556,7 +533,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
                        _INFO("TAC name : %s", tac_name.c_str());
                        _INFO("TAC version : %s", tac_version.c_str());
 
-                       bf::path tac_version_dir = bf::path(mOptUsrDotnet) / np;
+                       bf::path tac_version_dir = concatPath(__TAC_DIR, np);
                        isCreateDirectory = false;
                        if (!bf::exists(tac_version_dir)) {
                                _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
@@ -566,7 +543,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
                                }
                                isCreateDirectory = true;
                                createDirectories.push_back(tac_version_dir.string());
-                               std::string sha256_info = (tac_version_dir / bf::path("SHA256.info")).string();
+                               std::string sha256_info = (tac_version_dir / TAC_SHA_256_INFO).string();
                                std::ofstream ofs2(sha256_info, std::ios::app);
                                int assembly_count = 0;
                                for (auto& npAssemblyShaR2R : nugetPackagesAssembliesShaR2R) {
@@ -598,11 +575,11 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
 
                                if (count == 1) {
                                        sql = "UPDATE TAC SET NAME = '" + tac_name + "', VERSION = '" + tac_version + "', NUGET = '" + np + "' WHERE PKGID = '" + std::string(pkgId) + "' AND NAME = '" + tac_name + "';";
-                                       dbUpdate(tac_db, tacAppListDB, sql);
+                                       dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
                                } else {
                                        sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
                                                "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
-                                       dbInsert(tac_db, tacAppListDB, sql);
+                                       dbInsert(tac_db, TAC_APP_LIST_DB, sql);
                                }
                        } else {
                                _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
@@ -618,7 +595,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
                                        std::string r2r = npAssemblyShaR2R.substr(npAssemblyShaR2R.rfind('/') + 1);
                                        if (!strcmp(nuget_package.c_str(), np.c_str())) {
                                                assembly_count++;
-                                               std::string sha256_info = (tac_version_dir / bf::path("SHA256.info")).string();
+                                               std::string sha256_info = (tac_version_dir / TAC_SHA_256_INFO).string();
                                                std::ifstream ifs2(sha256_info);
                                                std::string get_str;
                                                if (ifs2.is_open()) {
@@ -651,11 +628,11 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
 
                                        if (count == 1) {
                                                sql = "UPDATE TAC SET NAME = '" + tac_name + "', VERSION = '" + tac_version + "', NUGET = '" + np + "' WHERE PKGID = '" + std::string(pkgId) + "' AND NAME = '" + tac_name + "';";
-                                               dbUpdate(tac_db, tacAppListDB, sql);
+                                               dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
                                        } else {
                                                sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
                                                        "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
-                                               dbInsert(tac_db, tacAppListDB, sql);
+                                               dbInsert(tac_db, TAC_APP_LIST_DB, sql);
                                        }
                                } else {
                                        _INFO("Different : %s", tac_name.c_str());
@@ -673,7 +650,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
 
                        if (!isExits) {
                                std::string sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "' AND NUGET = '" + unp + "';";
-                               dbDelete(tac_db, tacAppListDB, sql);
+                               dbDelete(tac_db, TAC_APP_LIST_DB, sql);
                        }
                }
 
@@ -693,9 +670,9 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *a
        _INFO("PackageID : %s", pkgId);
 
        status = "uninstall";
-       tac_db = dbCreate(tacAppListDB);
+       tac_db = dbCreate(TAC_APP_LIST_DB);
        if (tac_db) {
-               if (!dbOpen(tac_db, tacAppListDB)) {
+               if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
                        return 0;
                }
        } else {
@@ -704,10 +681,10 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *a
        }
 
        std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
-       updateTac = dbSelect(tac_db, tacAppListDB, sql);
+       updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
 
        sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
-       dbDelete(tac_db, tacAppListDB, sql);
+       dbDelete(tac_db, TAC_APP_LIST_DB, sql);
 
        if (updateTacDB(pkgId)) {
                return 0;
@@ -718,6 +695,8 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *a
 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
 {
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_REMOVED =====]");
+       _INFO("PackageID : %s", pkgId);
+
        status = "removed";
 
        PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
@@ -732,10 +711,10 @@ int install_Clean()
 int unInstall_Clean()
 {
        for (auto& unp : updateTac) {
-               bf::path current_tac = bf::path(mOptUsrDotnet) / unp.substr(0, unp.find('/'));
+               bf::path current_tac = bf::path(__TAC_DIR) / unp.substr(0, unp.find('/'));
                std::vector<std::string> exist_directory_name;
                for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-                       if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), mBackup.c_str()) != NULL) {
+                       if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), ".bck") != NULL) {
                                if (!removeAll(bck.path().string())) {
                                        _ERR("Failed to remove of %s", bck.path().c_str());
                                        return 0;
@@ -744,7 +723,7 @@ int unInstall_Clean()
                        }
                }
                for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-                       if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), mBackup.c_str()) == NULL) {
+                       if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), ".bck") == NULL) {
                                exist_directory_name.push_back(bck.path().string());
                                break;
                        }
@@ -765,10 +744,10 @@ int update_Clean()
 {
        if (!tacDB.empty()) {
                for (auto& np : tacDB) {
-                       bf::path current_tac = bf::path(mOptUsrDotnet) / np.substr(0, np.find('/'));
+                       bf::path current_tac = bf::path(__TAC_DIR) / np.substr(0, np.find('/'));
                        std::vector<std::string> exist_directory_name;
                        for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-                               if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), mBackup.c_str()) != NULL) {
+                               if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), ".bck") != NULL) {
                                        if (!removeAll(bck.path().string())) {
                                                _ERR("Failed to remove of %s", bck.path().c_str());
                                                return 0;
@@ -777,7 +756,7 @@ int update_Clean()
                                }
                        }
                        for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-                               if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), mBackup.c_str()) == NULL) {
+                               if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), ".bck") == NULL) {
                                        exist_directory_name.push_back(bck.path().string());
                                        break;
                                }
@@ -828,11 +807,11 @@ int install_Undo()
 int unInstall_Undo()
 {
        for (auto& unp : updateTac) {
-               for (auto& bck : bf::recursive_directory_iterator(bf::path(mOptUsrDotnet) / unp.substr(0, unp.find('/')))) {
-                       if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), mBackup.c_str()) != NULL) {
-                               if (!moveFile(bck.path(), bck.path().string().substr(0, bck.path().string().rfind(mBackup.c_str())))) {
+               for (auto& bck : bf::recursive_directory_iterator(bf::path(__TAC_DIR) / unp.substr(0, unp.find('/')))) {
+                       if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), ".bck") != NULL) {
+                               if (!moveFile(bck.path(), bck.path().string().substr(0, bck.path().string().rfind(".bck")))) {
                                        _ERR("Failed to move %s to %s",
-                                               bck.path().c_str(), bck.path().string().substr(0, bck.path().string().rfind(mBackup.c_str())).c_str());
+                                               bck.path().c_str(), bck.path().string().substr(0, bck.path().string().rfind(".bck")).c_str());
                                        return 0;
                                }
                                break;
@@ -852,11 +831,11 @@ int update_Undo()
        }
        if (!tacDB.empty()) {
                for (auto& np : tacDB) {
-                       for (auto& bck : bf::recursive_directory_iterator(bf::path(mOptUsrDotnet) / np.substr(0, np.find('/')))) {
-                               if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), mBackup.c_str()) != NULL) {
-                                       if (!moveFile(bck.path(), bck.path().string().substr(0, bck.path().string().rfind(mBackup.c_str())))) {
+                       for (auto& bck : bf::recursive_directory_iterator(bf::path(__TAC_DIR) / np.substr(0, np.find('/')))) {
+                               if (bf::exists(bck.path()) && bf::is_directory(bck.path()) && strstr(bck.path().c_str(), ".bck") != NULL) {
+                                       if (!moveFile(bck.path(), bck.path().string().substr(0, bck.path().string().rfind(".bck")))) {
                                                _ERR("Failed to move %s to %s",
-                                                       bck.path().c_str(), bck.path().string().substr(0, bck.path().string().rfind(mBackup.c_str())).c_str());
+                                                       bck.path().c_str(), bck.path().string().substr(0, bck.path().string().rfind(".bck")).c_str());
                                                return 0;
                                        }
                                        break;
index 8f1bca7..a4affd4 100644 (file)
@@ -20,7 +20,7 @@
 #ifdef  LOG_TAG
 #undef  LOG_TAG
 #endif
-#define LOG_TAG "NETCORE_INSTALLER_PLUGIN"
+#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
 
 #include <cstring>
 #include <pkgmgr-info.h>
index 8ad60ed..f8ef5c9 100644 (file)
@@ -389,9 +389,9 @@ int CoreRuntime::initialize(bool standalone)
        std::string appRoot = std::string("/proc/self/fd/") + std::to_string(fd);
        std::string appBin = concatPath(appRoot, "bin");
        std::string appLib = concatPath(appRoot, "lib");
-       std::string appTAC = concatPath(appBin, ".TAC.Release");
-       std::string probePath = appBin + ":" + appLib + ":" + appTAC;
-       std::string NIprobePath = appBin + APP_NI_SUB_DIR + ":" + appLib + APP_NI_SUB_DIR + ":" + appTAC;
+       std::string appTac = concatPath(appBin, TAC_SYMLINK_SUB_DIR);
+       std::string probePath = appBin + ":" + appLib + ":" + appTac;
+       std::string NIprobePath = concatPath(appBin, APP_NI_SUB_DIR) + ":" + concatPath(appLib, APP_NI_SUB_DIR) + ":" + appTac;
        std::string tpa = getTPA();
        std::string nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appBin + ":" + appLib + ":" + __nativeLibDirectory;
        std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid());
index 18f792d..ceba067 100644 (file)
 
 #include <algorithm>
 #include <string>
+#include <fstream>
 
 #include <pwd.h>
 #include <grp.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
 
-#include <fstream>
-#include <sys/smack.h>
-
 #include "ni_common.h"
 #include "path_manager.h"
 #include "plugin_manager.h"
@@ -45,7 +42,7 @@
 #ifdef  LOG_TAG
 #undef  LOG_TAG
 #endif
-#define LOG_TAG "NETCORE_INSTALLER_PLUGIN"
+#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
 
 #ifndef CROSSGEN_PATH
 #error "CROSSGEN_PATH is missed"
@@ -69,26 +66,6 @@ static void waitInterval()
        }
 }
 
-static void updateNiFileInfo(const std::string& dllPath, const std::string& niPath)
-{
-       char* label = NULL;
-
-       // change smack label
-       if (smack_getlabel(dllPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) {
-               if (smack_setlabel(niPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) {
-                       fprintf(stderr, "Fail to set smack label\n");
-               }
-               free(label);
-       }
-
-       // change owner and groups for generated ni file.
-       struct stat info;
-       if (!stat(dllPath.c_str(), &info)) {
-               if (chown(niPath.c_str(), info.st_uid, info.st_gid) == -1)
-                       fprintf(stderr, "Failed to change owner and group name\n");
-       }
-}
-
 static std::string getNiFilePath(const std::string& dllPath)
 {
        size_t index = dllPath.find_last_of(".");
@@ -116,11 +93,11 @@ static std::string getAppNIPath(const std::string& niPath)
 
        std::string prevPath = niPath.substr(0, index);
        std::string fileName = niPath.substr(index, niPath.length());
-       std::string niDirPath = prevPath + APP_NI_SUB_DIR;
+       std::string niDirPath = concatPath(prevPath, APP_NI_SUB_DIR);
 
        if (!isFileExist(niDirPath)) {
                if (mkdir(niDirPath.c_str(), 0755) == 0) {
-                       updateNiFileInfo(prevPath, niDirPath);
+                       updateAssemblyInfo(prevPath, niDirPath);
                } else {
                        fprintf(stderr, "Fail to create app ni directory (%s)\n", niDirPath.c_str());
                }
@@ -191,7 +168,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
                        // Do not use niExist() function to check whether ni file created or not.
                        // niEixst() return false for System.Private.Corelib.dll
                        if (isFileExist(absNiPath)) {
-                               updateNiFileInfo(absDllPath, absNiPath);
+                               updateAssemblyInfo(absDllPath, absNiPath);
                                return NI_ERROR_NONE;
                        } else {
                                fprintf(stderr, "Fail to create native image for %s\n", dllPath.c_str());
@@ -376,8 +353,8 @@ ni_error_e createNiUnderPkgRoot(const std::string& pkgId, bool enableR2R)
 
        std::string binDir = concatPath(pkgRoot, "bin");
        std::string libDir = concatPath(pkgRoot, "lib");
-       std::string appTAC = concatPath(binDir, ".TAC.Release");
-       std::string paths[] = {binDir, libDir, appTAC};
+       std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
+       std::string paths[] = {binDir, libDir, tacDir};
 
        createNiUnderDirs(paths, 3, enableR2R, true);
 
@@ -449,14 +426,14 @@ ni_error_e removeNiUnderPkgRoot(const std::string& pkgId)
 
        removeNiUnderDirs(paths, 2);
 
-       std::string binNIDir = binDir + APP_NI_SUB_DIR;
+       std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
        if (isFileExist(binNIDir)) {
                if (rmdir(binNIDir.c_str()) != 0) {
                        fprintf(stderr, "Failed to remove app ni dir [%s]\n", binNIDir.c_str());
                }
        }
 
-       std::string libNIDir = libDir + APP_NI_SUB_DIR;
+       std::string libNIDir = concatPath(libDir, APP_NI_SUB_DIR);
        if (isFileExist(libNIDir)) {
                if (rmdir(libNIDir.c_str()) != 0) {
                        fprintf(stderr, "Failed to remove app ni dir [%s]\n", libNIDir.c_str());
@@ -475,7 +452,7 @@ ni_error_e regenerateAppNI(bool enableR2R)
        if (ret != PMINFO_R_OK)
                return NI_ERROR_UNKNOWN;
 
-       ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, AOT_METADATA_VALUE);
+       ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, METADATA_VALUE);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
                return NI_ERROR_UNKNOWN;
index 98be18c..25e150c 100644 (file)
@@ -52,7 +52,7 @@ static void help(const char *argv0)
 {
        const char* helpDesc =
                "Usage: %s [args] <root paths or pkg name>\n"
-               "          --help                       - Display this screen\n"
+               "          --help               - Display this screen\n"
                "          --restore-db         - Restore TAC Database\n"
                "\n";
        printf(helpDesc, argv0, argv0, argv0, argv0, argv0);
index f18eb5a..b3b08f4 100644 (file)
@@ -145,7 +145,6 @@ std::vector<std::string> dbSelect(sqlite3 *tac_db, std::string path, std::string
        }
        while (sqlite3_step(stmt) == SQLITE_ROW) {
                str = (const char *) sqlite3_column_text(stmt, 2);
-               _DBG("Nuget : %s", (!str || !strlen(str)) ? NULL : strdup(str));
                updateDB.push_back((!str || !strlen(str)) ? NULL : strdup(str));
        }
        dbFinalize(stmt);
index 45a61f6..a33eec2 100644 (file)
@@ -22,6 +22,7 @@
 #include <strings.h>
 #include <pkgmgr-info.h>
 #include <pkgmgr_installer_info.h>
+#include <sys/smack.h>
 
 #include <cstdlib>
 #include <cstring>
@@ -210,7 +211,7 @@ void scanFilesInDir(const std::string& directory, FileReader reader, unsigned in
        struct dirent* entry;
        bool isDir;
 
-       if (strstr(directory.c_str(), ".TAC.Release") != NULL)
+       if (strstr(directory.c_str(), TAC_SYMLINK_SUB_DIR) != NULL)
                return; // skip nitool --regen-all-app (--r2r)
 
        dir = opendir(directory.c_str());
@@ -252,6 +253,26 @@ void scanFilesInDir(const std::string& directory, FileReader reader, unsigned in
        closedir(dir);
 }
 
+void updateAssemblyInfo(const std::string& getPath, const std::string& setPath)
+{
+       char* label = NULL;
+
+       // change smack label
+       if (smack_getlabel(getPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) {
+               if (smack_setlabel(setPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) {
+                       fprintf(stderr, "Fail to set smack label\n");
+               }
+               free(label);
+       }
+
+       // change owner and groups for generated ni file.
+       struct stat info;
+       if (!stat(getPath.c_str(), &info)) {
+               if (chown(setPath.c_str(), info.st_uid, info.st_gid) == -1)
+                       fprintf(stderr, "Failed to change owner and group name\n");
+       }
+}
+
 static bool setOwnership(const bf::path& path, uid_t uid, gid_t gid) {
        int fd = open(path.c_str(), O_RDONLY);
        if (fd < 0) {
index 41a5138..4133845 100644 (file)
@@ -116,7 +116,6 @@ rm -rf %{buildroot}
 mkdir -p %{buildroot}%{_framework_dir}
 mv Init/bin/Release/Tizen.Init.dll %{buildroot}%{_framework_dir}
 
-
 mkdir -p %{buildroot}%{_tac_dir}
 mkdir -p %{buildroot}%{_native_lib_dir}
 ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so