#include <fstream>
#include <pkgmgr-info.h>
#include <pkgmgr_installer_info.h>
-#include <json/json.h>
#include "log.h"
#include "utils.h"
#include "ni_common.h"
#include "tac_common.h"
#include "db_manager.h"
+#include "path_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
static sqlite3 *tac_db = NULL;
std::vector<std::string> restoreNuget;
-std::vector<std::string> enableNuget;
void cleanupDirectory()
{
std::vector<std::string> removeNuget;
- for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
- bool isExist = false;
- for (auto& restore : restoreNuget) {
- if (!bf::is_directory(nuget.path())) {
- isExist = true;
+ try {
+ for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
+ bool isExist = false;
+ std::string nugetPath = nuget.path().string();
+ for (auto& restore : restoreNuget) {
+ if (!bf::is_directory(nugetPath)) {
+ isExist = true;
+ }
+ if (strstr(nugetPath.c_str(), restore.c_str()) != NULL) {
+ isExist = true;
+ break;
+ }
}
- if (strstr(nuget.path().c_str(), restore.c_str()) != NULL) {
- isExist = true;
- break;
+ if (!isExist) {
+ removeNuget.push_back(nugetPath);
}
}
- if (!isExist) {
- removeNuget.push_back(nuget.path().string());
- }
- }
-
- for (auto& rm : removeNuget) {
- if (!removeAll(rm)) {
- _ERR("Failed to remove of %s", rm.c_str());
- }
- }
- removeNuget.clear();
-}
-void depsJsonParser(std::string pkgId, std::string depsJsonPath, std::string execName, bool isRestore)
-{
- std::ifstream ifs(depsJsonPath);
- Json::CharReaderBuilder reader;
- Json::Value root;
- std::string error;
- if (ifs.is_open()) {
- if (!Json::parseFromStream(reader, ifs, &root, &error)) {
- _INFO("Failed to parse of deps.json");
- ifs.close();
- return;
- }
- const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
- const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
- for (auto& nuget : nugetPackages.getMemberNames()) {
- 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;
- } else {
- const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
- if (assemblies != Json::nullValue) {
- const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
- bool isDependency = false;
- for (auto& dependency : dependencies.getMemberNames()) {
- if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) != NULL ||
- strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) != NULL) {
- continue;
- } else {
- isDependency = true;
- }
- }
- if (!isDependency) {
- _INFO("PackageId : [%s] / Nuget package : [%s]", pkgId.c_str(), nuget.c_str());
- std::string name = nuget.substr(0, nuget.find('/'));
- std::string version = nuget.substr(nuget.rfind('/') + 1);
- std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES ('" + pkgId + "', '" + nuget + "', '" + name + "', '" + version + "');";
- if (isRestore) {
- if (tac_db) {
- dbInsert(tac_db, TAC_APP_LIST_RESTORE_DB, sql);
- restoreNuget.push_back(concatPath(__TAC_DIR, name));
- }
- } else {
- std::string nugetPath = concatPath(__TAC_DIR, nuget);
- if (bf::exists(nugetPath)) {
- for (auto& assembly : assemblies.getMemberNames()) {
- std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
- std::string originPath = concatPath(nugetPath, assemblyName);
- if (bf::exists(originPath)) {
- enableNuget.push_back(originPath);
- }
- }
- }
- }
- }
- }
+ for (auto& rm : removeNuget) {
+ if (!removeAll(rm)) {
+ _ERR("Failed to remove of %s", rm.c_str());
}
}
- ifs.close();
+ removeNuget.clear();
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return;
}
}
}
execName = std::string(exec).substr(std::string(exec).rfind('/') + 1);
- std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
- std::string depsJsonPath = concatPath(rootPath, depsJsonName);
- if (bf::exists(depsJsonPath)) {
- depsJsonParser(pkgId, depsJsonPath, execName, true);
+ std::vector<std::string> parserData;
+ for (auto& npAssembly : depsJsonParser(rootPath, execName, getTPA())) {
+ std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
+ parserData.push_back(nugetPackage);
+ }
+ std::sort(parserData.begin(), parserData.end());
+ parserData.erase(unique(parserData.begin(), parserData.end()), parserData.end());
+
+ for (auto& nuget : parserData) {
+ if (tac_db) {
+ std::string name = nuget.substr(0, nuget.find('/'));
+ std::string version = nuget.substr(nuget.rfind('/') + 1);
+ std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
+ "VALUES ('" + std::string(pkgId) + "', '" + nuget + "', '" + name + "', '" + version + "');";
+ dbInsert(tac_db, TAC_APP_LIST_RESTORE_DB, sql);
+ restoreNuget.push_back(concatPath(__TAC_DIR, name));
+ }
}
+ parserData.clear();
return 0;
}
return TAC_ERROR_UNKNOWN;
}
+ if (initializePathManager(std::string(), std::string(), std::string())) {
+ fprintf(stderr, "Fail to initialize PathManger");
+ return TAC_ERROR_UNKNOWN;
+ }
+
tac_db = dbCreate(TAC_APP_LIST_RESTORE_DB);
if (tac_db) {
if (!dbOpen(tac_db, TAC_APP_LIST_RESTORE_DB)) {
}
if (!copyFile(TAC_APP_LIST_RESTORE_DB, TAC_APP_LIST_DB)) {
- fprintf(stderr, "Failed to move of %s", TAC_APP_LIST_DB);
+ fprintf(stderr, "Failed to copy of %s", TAC_APP_LIST_DB);
return TAC_ERROR_UNKNOWN;
}
if (!removeFile(TAC_APP_LIST_RESTORE_DB)) {
std::string dbJournal = TAC_APP_LIST_DB + std::string("-journal");
if (!copyFile(dbRestoreJournal, dbJournal)) {
- fprintf(stderr, "Failed to move of %s", dbJournal.c_str());
+ fprintf(stderr, "Failed to copy of %s", dbJournal.c_str());
return TAC_ERROR_UNKNOWN;
}
if (!removeFile(dbRestoreJournal)) {
std::string binDir = concatPath(pkgRoot, "bin");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
if (bf::exists(tacDir)) {
- for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
- std::string symPath = symlinkAssembly.path().string();
- if (bf::is_symlink(symPath)) {
- if (isNativeImage(symPath)) {
- tacNativeImage.push_back(symPath);
+ try {
+ for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+ std::string symPath = symlinkAssembly.path().string();
+ if (bf::is_symlink(symPath)) {
+ if (isNativeImage(symPath)) {
+ tacNativeImage.push_back(symPath);
+ }
}
}
- }
- for (auto& path : tacNativeImage) {
- if (!removeFile(path)) {
- fprintf(stderr, "Failed to remove of %s", path.c_str());
- return TAC_ERROR_UNKNOWN;
+ for (auto& path : tacNativeImage) {
+ if (!removeFile(path)) {
+ fprintf(stderr, "Failed to remove of %s", path.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
}
+ tacNativeImage.clear();
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return TAC_ERROR_UNKNOWN;
}
}
- tacNativeImage.clear();
return TAC_ERROR_NONE;
}
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
if (bf::exists(tacDir)) {
- for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
- std::string symPath = symlinkAssembly.path().string();
- if (bf::is_symlink(symPath)) {
- 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) {
- fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
- return TAC_ERROR_UNKNOWN;
+ try {
+ for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+ std::string symPath = symlinkAssembly.path().string();
+ if (bf::is_symlink(symPath)) {
+ 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) {
+ fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
}
- }
- std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
- if (!bf::exists(symNIPath)) {
- bf::create_symlink(originNiPath, symNIPath);
- fprintf(stderr, "%s symbolic link file generated successfully.\n", symNIPath.c_str());
- updateAssemblyInfo(tacDir.c_str(), symNIPath.c_str(), true);
-
- std::string NIFileName = symNIPath.substr(symNIPath.rfind('/') + 1);
- if (!removeFile(concatPath(binNIDir, NIFileName))) {
- fprintf(stderr, "Failed to remove of %s\n", concatPath(binNIDir, NIFileName).c_str());
- return TAC_ERROR_UNKNOWN;
+ std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
+ if (!bf::exists(symNIPath)) {
+ bf::create_symlink(originNiPath, symNIPath);
+ fprintf(stderr, "%s symbolic link file generated successfully.\n", symNIPath.c_str());
+ updateAssemblyInfo(tacDir.c_str(), symNIPath.c_str(), true);
+
+ std::string NIFileName = symNIPath.substr(symNIPath.rfind('/') + 1);
+ if (!removeFile(concatPath(binNIDir, NIFileName))) {
+ fprintf(stderr, "Failed to remove of %s\n", concatPath(binNIDir, NIFileName).c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
}
}
}
}
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return TAC_ERROR_UNKNOWN;
}
}
return TAC_ERROR_NONE;
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
if (bf::exists(tacDir)) {
- for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
- std::string symPath = symlinkAssembly.path().string();
- std::string fileName = symlinkAssembly.path().filename().string();
- if (bf::is_symlink(symPath)) {
- std::string originPath = bf::read_symlink(symPath).string();
- if (!isNativeImage(symPath)) {
- if (!copyFile(originPath, concatPath(binDir, fileName))) {
- fprintf(stderr, "Failed to copy of %s\n", concatPath(binDir, fileName).c_str());
- return TAC_ERROR_UNKNOWN;
- }
- updateAssemblyInfo(binDir.c_str(), concatPath(binDir, fileName).c_str());
- } else {
- if (!copyFile(originPath, concatPath(binNIDir, fileName))) {
- fprintf(stderr, "Failed to copy of %s\n", concatPath(binNIDir, fileName).c_str());
- return TAC_ERROR_UNKNOWN;
+ try {
+ for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+ std::string symPath = symlinkAssembly.path().string();
+ std::string fileName = symlinkAssembly.path().filename().string();
+ if (bf::is_symlink(symPath)) {
+ std::string originPath = bf::read_symlink(symPath).string();
+ if (!isNativeImage(symPath)) {
+ std::string dllPath = concatPath(binDir, fileName);
+ if (!copyFile(originPath, dllPath)) {
+ fprintf(stderr, "Failed to copy of %s\n", dllPath.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+ updateAssemblyInfo(binDir.c_str(), concatPath(binDir, fileName).c_str());
+ } else {
+ std::string niPath = concatPath(binNIDir, fileName);
+ if (!copyFile(originPath, niPath)) {
+ fprintf(stderr, "Failed to copy of %s\n", niPath.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+ updateAssemblyInfo(binDir.c_str(), niPath.c_str());
}
- updateAssemblyInfo(binDir.c_str(), concatPath(binNIDir, fileName).c_str());
}
}
+ if (!removeAll(tacDir)) {
+ fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return TAC_ERROR_UNKNOWN;
}
}
- if (!removeAll(tacDir)) {
- fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str());
- return TAC_ERROR_UNKNOWN;
- }
return TAC_ERROR_NONE;
}
tac_error_e enableTACPackage(const std::string& pkgId)
{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
+ std::string rootPath;
+ if (getRootPath(pkgId, rootPath) < 0) {
return TAC_ERROR_INVALID_PACKAGE;
}
return TAC_ERROR_INVALID_PACKAGE;
}
+ if (initializePathManager(std::string(), std::string(), std::string())) {
+ fprintf(stderr, "Fail to initialize PathManger");
+ return TAC_ERROR_UNKNOWN;
+ }
+
if (!strcmp(metaValue.c_str(), "true")) {
- 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)) {
}
updateAssemblyInfo(binDir.c_str(), tacDir.c_str());
- std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
- std::string depsJsonPath = concatPath(pkgRoot, depsJsonName);
- if (bf::exists(depsJsonPath)) {
- depsJsonParser(pkgId, depsJsonPath, execName, false);
+ std::vector<std::string> enableNuget;
+ for (auto& npAssembly : depsJsonParser(rootPath, execName, getTPA())) {
+ std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
+ std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
+ std::string nugetPath = concatPath(__TAC_DIR, nugetPackage);
+ if (bf::exists(nugetPath)) {
+ std::string originPath = concatPath(nugetPath, assemblyName);
+ if (bf::exists(originPath)) {
+ enableNuget.push_back(originPath);
+ }
+ }
}
for (auto& originPath : enableNuget) {
_ERR("Failed to remove of %s", tacDir.c_str());
}
}
+ enableNuget.clear();
}
} else {
fprintf(stderr, "The metadata key is missing or the metadata value is false of [%s]\n", pkgId.c_str());