#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;
std::string status = "";
std::string rootPath;
std::string execName;
-bf::path binPath;
+std::string binPath;
bool isCreateDirectory = false;
static sqlite3 *tac_db = NULL;
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;
}
}
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;
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;
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);
}
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;
}
_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;
}
}
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;
}
if (getRootPath(std::string(pkgId), rootPath) < 0) {
return 0;
} else {
- binPath = rootPath / bf::path("bin");
+ binPath = concatPath(rootPath, "bin");
}
if (!metadataCheck(list)) {
if (depsJsonParser()) {
}
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 {
_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;
}
}
_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());
}
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) {
}
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;
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()) {
}
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());
}
int ret;
int count = 0;
if (tac_db) {
- if (!dbOpen(tac_db, tacAppListDB)) {
+ if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
return 0;
}
} else {
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;
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");
}
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 {
}
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;
}
}
_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());
}
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) {
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());
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()) {
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());
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);
}
}
_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 {
}
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;
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);
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;
}
}
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;
}
{
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;
}
}
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;
}
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;
}
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;