util/plugin_manager.cc
util/path_manager.cc
util/log_manager.cc
- util/db_manager.cc
)
ADD_LIBRARY(${DOTNET_LAUNCHER_UTIL} SHARED ${${DOTNET_LAUNCHER_UTIL}_SOURCE_FILES})
SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER_UTIL} PROPERTIES COMPILE_FLAGS "-fPIC")
PROPERTIES SKIP_BUILD_RPATH TRUE
) # remove rpath option that is automatically generated by cmake.
+SET(TAC_COMMON "tac_common")
+SET(${TAC_COMMON}_SOURCE_FILES
+ tool/tac_common.cc
+ util/db_manager.cc
+)
+ADD_LIBRARY(${TAC_COMMON} SHARED ${${TAC_COMMON}_SOURCE_FILES})
+SET_TARGET_PROPERTIES(${TAC_COMMON} PROPERTIES COMPILE_FLAGS "-fPIC")
+TARGET_LINK_LIBRARIES(${TAC_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL})
+
SET(NI_COMMON "ni_common")
SET(${NI_COMMON}_SOURCE_FILES
tool/ni_common.cc
- tool/tac_common.cc
)
ADD_LIBRARY(${NI_COMMON} SHARED ${${NI_COMMON}_SOURCE_FILES})
SET_TARGET_PROPERTIES(${NI_COMMON} PROPERTIES COMPILE_FLAGS "-fPIC")
-TARGET_LINK_LIBRARIES(${NI_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL})
+TARGET_LINK_LIBRARIES(${NI_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${TAC_COMMON})
SET(NITOOL "nitool")
SET(${NITOOL}_SOURCE_FILES
)
ADD_LIBRARY(${PREFER_NUGET_CACHE_PLUGIN} SHARED ${${PREFER_NUGET_CACHE_PLUGIN}_SOURCE_FILES})
SET_TARGET_PROPERTIES(${PREFER_NUGET_CACHE_PLUGIN} PROPERTIES COMPILE_FLAGS "-fPIC")
-TARGET_LINK_LIBRARIES(${PREFER_NUGET_CACHE_PLUGIN} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL})
+TARGET_LINK_LIBRARIES(${PREFER_NUGET_CACHE_PLUGIN} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${TAC_COMMON})
CONFIGURE_FILE(dotnet-launcher.pc.in dotnet-launcher.pc @ONLY)
INSTALL(TARGETS ${DOTNET_LAUNCHER_UTIL} DESTINATION ${LIBDIR})
INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR})
+INSTALL(TARGETS ${TAC_COMMON} DESTINATION ${LIBDIR})
INSTALL(TARGETS ${NI_COMMON} DESTINATION ${LIBDIR})
INSTALL(TARGETS ${NITOOL} DESTINATION ${BINDIR})
INSTALL(TARGETS ${TPATOOL} DESTINATION ${BINDIR})
#define QUERY_MAX_LEN 4096
sqlite3* dbCreate(std::string path);
-bool dbOpen(sqlite3 *tac_db, std::string path);
+sqlite3* dbOpen(std::string path);
void dbClose(sqlite3 *tac_db);
void dbRollback(sqlite3 *tac_db);
bool dbUpdate(sqlite3 *tac_db, std::string path, std::string query);
*/
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
+ * @return ni_error_e
+ */
+ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags);
+
/**
* @brief create native images for all DLLs under directories
* @param[i] rootPaths paths to directories
*/
ni_error_e regenerateAppNI(DWORD flags);
+/**
+ * @brief regenerate native image of TAC for all shared assembly.
+ * @return ni_error_e
+ */
+ni_error_e regenerateTACNI(DWORD flags);
+
#endif /* __NI_COMMON_H__ */
#include <functional>
+#ifndef DWORD
+#define DWORD uint32_t
+#endif
+
typedef enum {
TAC_ERROR_NONE = 0,
TAC_ERROR_INVALID_PARAMETER = -1,
*/
tac_error_e resetTACPackage(const std::string& pkgId);
-/**
- * @brief creates a symbolic link file, the native image of TAC for specific package.
- * @param[i] pkgId package ID
- * @return tac_error_e
- */
-tac_error_e createTACPackage(const std::string& pkgId, DWORD flags);
-
-/**
- * @brief regenerate native image of TAC for all shared assembly.
- * @return tac_error_e
- */
-tac_error_e regenerateTAC(DWORD flags);
-
/**
* @brief disable tac feature.
* @param[i] pkgId package ID
*/
tac_error_e enableTACPackage(const std::string& pkgId);
+/**
+ * @brief .deps.json file parser
+ * @param[in] root path
+ * @param[in] exec name
+ * @param[in] tpa list
+ * @return std::vector<std::string> parser data
+ */
+std::vector<std::string> depsJsonParser(std::string rootPath, std::string execName, std::string tpaList);
+
#endif /* __TAC_COMMON_H__ */
*/
bool removeAll(const bf::path& path);
-/**
- * @brief .deps.json file parser
- * @param[in] root path
- * @param[in] exec name
- * @param[in] tpa list
- * return std::vector<std::string> parser data
- */
-std::vector<std::string> depsJsonParser(std::string rootPath, std::string execName, std::string tpaList);
-
#endif /* __UTILS_H__ */
#include "db_manager.h"
#include "path_manager.h"
#include "plugin_manager.h"
+#include "tac_common.h"
#include <cstring>
#include <fstream>
std::string rootPath;
std::string execName;
std::string binPath;
-bool isCreateDirectory = false;
static sqlite3 *tac_db = NULL;
bool metadataCheck(GList *list)
free(buffer);
}
-int createSymlink(std::string tac_version_dir, std::string np)
+int copyNCreateSymlink(std::string tac_version_dir, std::string np, bool is_create_tac_dir)
{
uid_t uid = 0;
if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
if (!strcmp(nuget_package.c_str(), np.c_str())) {
if (bf::exists(concatPath(binPath, assembly))) {
- if (isCreateDirectory) {
+ if (is_create_tac_dir) {
if (!copyFile(concatPath(binPath, assembly), concatPath(tac_version_dir, assembly))) {
_ERR("Failed to copy of %s", assembly.c_str());
return -1;
status = "install";
tac_db = dbCreate(TAC_APP_LIST_DB);
- if (tac_db) {
- if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
- _ERR("Sqlite open error");
- return 0;
- }
- } else {
+ if (!tac_db) {
_ERR("Sqlite create error");
return 0;
}
std::string tac_version_dir = concatPath(__TAC_DIR, np);
std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
- isCreateDirectory = false;
if (!bf::exists(tac_version_dir)) {
_INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
if (!createDir(tac_version_dir)) {
_ERR("Cannot create directory: %s", tac_version_dir.c_str());
return 0;
}
- isCreateDirectory = true;
createDirectories.push_back(tac_version_dir);
std::ofstream ofs(sha256_info, std::ios::app);
int assembly_count = 0;
ofs << assembly_count << std::endl;
ofs.close();
- if (createSymlink(tac_version_dir, np) < 0) {
+ if (copyNCreateSymlink(tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
!strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
_INFO("Same nuget : %s", np.c_str());
- if (createSymlink(tac_version_dir, np) < 0) {
+ if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
_ERR("Failed to create symlink");
return -1;
}
{
for (auto& unp : updateTac) {
int count = -1;
- if (tac_db) {
- if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
- _ERR("Sqlite open error");
- return -1;
- }
- } else {
- _ERR("Sqlite create error");
- return -1;
- }
std::string sql = "SELECT COUNT(NUGET) FROM TAC WHERE NUGET = '" + unp + "';";
int ret = sqlite3_exec(tac_db, sql.c_str(), sqliteCb, &count, NULL);
if (ret != SQLITE_OK) {
status = "update";
tac_db = dbCreate(TAC_APP_LIST_DB);
- if (tac_db) {
- if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
- _ERR("Sqlite open error");
- return 0;
- }
- } else {
- _ERR("Sqlite create error");
+ if (!tac_db) {
+ _ERR("Sqlite open error");
return 0;
}
- std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
- updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
-
if (tacDB.empty()) {
- sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ std::string sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
dbDelete(tac_db, TAC_APP_LIST_DB, sql);
if (updateTacDB(pkgId) < 0) {
return -1;
}
} else {
+ std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
+
for (auto& np : tacDB) {
std::string tac_name = np.substr(0, np.find('/'));
std::string tac_version = np.substr(np.rfind('/') + 1);
std::string tac_version_dir = concatPath(__TAC_DIR, np);
std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
- isCreateDirectory = false;
if (!bf::exists(tac_version_dir)) {
_INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
if (!createDir(tac_version_dir)) {
_ERR("Cannot create directory: %s", tac_version_dir.c_str());
return 0;
}
- isCreateDirectory = true;
createDirectories.push_back(tac_version_dir);
std::ofstream ofs(sha256_info, std::ios::app);
int assembly_count = 0;
}
ofs << assembly_count << std::endl;
ofs.close();
- if (createSymlink(tac_version_dir, np) < 0) {
+ if (copyNCreateSymlink(tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
!strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
_INFO("Same nuget : %s", np.c_str());
- if (createSymlink(tac_version_dir, np) < 0) {
+ if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
_ERR("Failed to create symlink");
return -1;
}
_INFO("PackageID : %s", pkgId);
status = "uninstall";
- tac_db = dbCreate(TAC_APP_LIST_DB);
- if (tac_db) {
- if (!dbOpen(tac_db, TAC_APP_LIST_DB)) {
- _ERR("Sqlite open error");
- return 0;
- }
- } else {
- _ERR("Sqlite create error");
+ tac_db = dbOpen(TAC_APP_LIST_DB);
+ if (!tac_db) {
+ _ERR("Sqlite open error");
return 0;
}
regenerateAppNI(flags);
return 0;
} else if (cmdOptionExists(argv, argv+argc, "--tac-regen-all")) {
- regenerateTAC(flags);
+ regenerateTACNI(flags);
return 0;
} else if (cmdOptionExists(argv, argv+argc, "--tac-restore-db")) {
restoreTACDB();
fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
return -1;
}
- ret = createTACPackage(pkg, flags);
+ ret = createTACPkgRoot(pkg, flags);
if (ret == TAC_ERROR_INVALID_PACKAGE) {
fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
return -1;
fprintf(stderr, "Complete make application to native image\n");
}
- if (createTACPackage(pkgId, *pFlags) != TAC_ERROR_NONE) {
+ if (createTACPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) {
fprintf(stderr, "Failed to generate symbolic link file [%s]\n", pkgId);
return -1;
}else {
scanFilesInDir(rootPaths[i], convert, -1);
}
} catch (const bf::filesystem_error& error) {
- fprintf(stderr, "Failed to recursive directory: %s", error.what());
+ fprintf(stderr, "Failed to recursive directory: %s\n", error.what());
return;
}
}
+ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags)
+{
+ std::string pkgRoot;
+ if (getRootPath(pkgId, pkgRoot) < 0) {
+ return NI_ERROR_INVALID_PACKAGE;
+ }
+
+ std::string binDir = concatPath(pkgRoot, "bin");
+ std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
+ std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
+ if (bf::exists(tacDir)) {
+ 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, flags) != NI_ERROR_NONE) {
+ fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
+ return NI_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 NI_ERROR_UNKNOWN;
+ }
+ }
+ }
+ }
+ }
+ } catch (const bf::filesystem_error& error) {
+ fprintf(stderr, "Failed to recursive directory: %s\n", error.what());
+ return NI_ERROR_UNKNOWN;
+ }
+ }
+ return NI_ERROR_NONE;
+}
+
void createNiUnderDirs(const std::string rootPaths[], int count, DWORD flags)
{
createCoreLibNI(flags);
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
return NI_ERROR_NONE;
}
+
+ni_error_e regenerateTACNI(DWORD flags)
+{
+ const std::string tacDir[] = {__TAC_DIR};
+ removeNiUnderDirs(tacDir, 1);
+ createNiUnderTAC(tacDir, 1, flags);
+ return NI_ERROR_NONE;
+}
*/
#include <fstream>
+#include <json/json.h>
#include <pkgmgr-info.h>
#include <pkgmgr_installer_info.h>
#include "log.h"
#include "utils.h"
-#include "ni_common.h"
#include "tac_common.h"
#include "db_manager.h"
#include "path_manager.h"
#undef __XSTR
static sqlite3 *tac_db = NULL;
-std::vector<std::string> restoreNuget;
+std::vector<std::string> restore_nuget;
-void cleanupDirectory()
+static void cleanupDirectory()
{
std::vector<std::string> removeNuget;
try {
for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
bool isExist = false;
std::string nugetPath = nuget.path().string();
- for (auto& restore : restoreNuget) {
+ for (auto& restore : restore_nuget) {
if (!bf::is_directory(nugetPath)) {
isExist = true;
}
- if (strstr(nugetPath.c_str(), restore.c_str()) != NULL) {
+ if (!strcmp(nugetPath.c_str(), restore.c_str()) ||
+ !strcmp(nugetPath.c_str(), restore.substr(0, restore.rfind('/')).c_str())) {
isExist = true;
break;
}
for (auto& rm : removeNuget) {
if (!removeAll(rm)) {
- _ERR("Failed to remove of %s", rm.c_str());
+ fprintf(stderr, "Failed to remove of %s\n", rm.c_str());
}
}
removeNuget.clear();
} catch (const bf::filesystem_error& error) {
- _ERR("Failed to recursive directory: %s", error.what());
+ fprintf(stderr, "Failed to recursive directory: %s\n", error.what());
return;
}
}
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));
+ restore_nuget.push_back(concatPath(__TAC_DIR, nuget));
}
}
parserData.clear();
tac_error_e restoreTACDB()
{
if (!removeFile(TAC_APP_LIST_RESTORE_DB)) {
- fprintf(stderr, "Failed to remove of %s", TAC_APP_LIST_RESTORE_DB);
+ fprintf(stderr, "Failed to remove of %s\n", TAC_APP_LIST_RESTORE_DB);
return TAC_ERROR_UNKNOWN;
}
std::string dbRestoreJournal = TAC_APP_LIST_RESTORE_DB + std::string("-journal");
if (!removeFile(dbRestoreJournal)) {
- fprintf(stderr, "Failed to remove of %s", dbRestoreJournal.c_str());
+ fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str());
return TAC_ERROR_UNKNOWN;
}
if (initializePathManager(std::string(), std::string(), std::string())) {
- fprintf(stderr, "Fail to initialize PathManger");
+ fprintf(stderr, "Fail to initialize PathManger\n");
return TAC_ERROR_UNKNOWN;
}
tac_db = dbCreate(TAC_APP_LIST_RESTORE_DB);
- if (tac_db) {
- if (!dbOpen(tac_db, TAC_APP_LIST_RESTORE_DB)) {
- return TAC_ERROR_UNKNOWN;
- }
- } else {
+ if (!tac_db) {
+ fprintf(stderr, "Sqlite create error\n");
return TAC_ERROR_UNKNOWN;
}
}
if (!copyFile(TAC_APP_LIST_RESTORE_DB, TAC_APP_LIST_DB)) {
- fprintf(stderr, "Failed to copy of %s", TAC_APP_LIST_DB);
+ fprintf(stderr, "Failed to copy of %s\n", TAC_APP_LIST_DB);
return TAC_ERROR_UNKNOWN;
}
if (!removeFile(TAC_APP_LIST_RESTORE_DB)) {
- fprintf(stderr, "Failed to remove of %s", TAC_APP_LIST_RESTORE_DB);
+ fprintf(stderr, "Failed to remove of %s\n", TAC_APP_LIST_RESTORE_DB);
return TAC_ERROR_UNKNOWN;
}
std::string dbJournal = TAC_APP_LIST_DB + std::string("-journal");
if (!copyFile(dbRestoreJournal, dbJournal)) {
- fprintf(stderr, "Failed to copy of %s", dbJournal.c_str());
+ fprintf(stderr, "Failed to copy of %s\n", dbJournal.c_str());
return TAC_ERROR_UNKNOWN;
}
if (!removeFile(dbRestoreJournal)) {
- fprintf(stderr, "Failed to remove of %s", dbRestoreJournal.c_str());
+ fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str());
return TAC_ERROR_UNKNOWN;
}
}
for (auto& path : tacNativeImage) {
if (!removeFile(path)) {
- fprintf(stderr, "Failed to remove of %s", path.c_str());
+ fprintf(stderr, "Failed to remove of %s\n", path.c_str());
return TAC_ERROR_UNKNOWN;
}
}
tacNativeImage.clear();
} catch (const bf::filesystem_error& error) {
- _ERR("Failed to recursive directory: %s", error.what());
+ fprintf(stderr, "Failed to recursive directory: %s\n", error.what());
return TAC_ERROR_UNKNOWN;
}
}
return TAC_ERROR_NONE;
}
-tac_error_e createTACPackage(const std::string& pkgId, DWORD flags)
-{
- std::string pkgRoot;
- if (getRootPath(pkgId, pkgRoot) < 0) {
- return TAC_ERROR_INVALID_PACKAGE;
- }
-
- std::string binDir = concatPath(pkgRoot, "bin");
- std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
- std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
- if (bf::exists(tacDir)) {
- 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, flags) != 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;
- }
- }
- }
- }
- }
- } catch (const bf::filesystem_error& error) {
- _ERR("Failed to recursive directory: %s", error.what());
- return TAC_ERROR_UNKNOWN;
- }
- }
- return TAC_ERROR_NONE;
-}
-
-tac_error_e regenerateTAC(DWORD flags)
-{
- const std::string tacDir[] = {__TAC_DIR};
- removeNiUnderDirs(tacDir, 1);
- createNiUnderTAC(tacDir, 1, flags);
- return TAC_ERROR_NONE;
-}
-
tac_error_e disableTACPackage(const std::string& pkgId)
{
std::string pkgRoot;
return TAC_ERROR_UNKNOWN;
}
} catch (const bf::filesystem_error& error) {
- _ERR("Failed to recursive directory: %s", error.what());
+ fprintf(stderr, "Failed to recursive directory: %s\n", error.what());
return TAC_ERROR_UNKNOWN;
}
}
}
if (initializePathManager(std::string(), std::string(), std::string())) {
- fprintf(stderr, "Fail to initialize PathManger");
+ fprintf(stderr, "Fail to initialize PathManger\n");
return TAC_ERROR_UNKNOWN;
}
}
if (enableNuget.empty()) {
if (!removeAll(tacDir)) {
- _ERR("Failed to remove of %s", tacDir.c_str());
+ fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str());
}
}
enableNuget.clear();
}
return TAC_ERROR_NONE;
}
+
+//Parser the .deps.json file to get nuget information.
+std::vector<std::string> depsJsonParser(std::string rootPath, std::string execName, std::string tpaList)
+{
+ std::vector<std::string> tpaAssemblies;
+ splitPath(tpaList, tpaAssemblies);
+
+ std::vector<std::string> parserData;
+ std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
+ std::string depsJsonPath = concatPath(rootPath, depsJsonName);
+ try {
+ if (bf::exists(depsJsonPath)) {
+ std::ifstream ifs(depsJsonPath);
+ Json::CharReaderBuilder reader;
+ Json::Value root;
+ std::string error;
+ if (ifs.is_open()) {
+ if (!Json::parseFromStream(reader, ifs, &root, &error)) {
+ _ERR("Failed to parse of deps.json");
+ ifs.close();
+ tpaAssemblies.clear();
+ return parserData;
+ }
+ const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
+ const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
+ std::vector<std::string> appDependencies;
+ for (auto& nuget : nugetPackages.getMemberNames()) {
+ if (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) {
+ const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
+ if (assemblies != Json::nullValue) {
+ const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
+ for (auto& dependency : dependencies.getMemberNames()) {
+ appDependencies.push_back(dependency);
+ }
+ }
+ }
+ }
+ for (auto& nuget : nugetPackages.getMemberNames()) {
+ //Skip the nuget package related to Tizen
+ 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) {
+ const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
+ if (assemblies != Json::nullValue) {
+ const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
+ bool hasDependency = false;
+ for (auto& dependency : dependencies.getMemberNames()) {
+ //Skip the nugget package that is dependent on another nuget package
+ if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
+ strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) == NULL) {
+ hasDependency = true;
+ for (auto& ad : appDependencies) {
+ if (!strcmp(ad.c_str(), dependency.c_str())) {
+ hasDependency = true;
+ break;
+ } else {
+ hasDependency = false;
+ }
+ }
+ if (hasDependency) break;
+ }
+ }
+ if (!hasDependency) {
+ bool isExistTpaAssembly = false;
+ for (auto& assembly : assemblies.getMemberNames()) {
+ std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
+ //Skip the assembly present in the TPA list
+ for (auto& tpa : tpaAssemblies) {
+ if (!strcmp(replaceAll(tpa, ".ni.dll", ".dll").c_str(), assembly.c_str())) {
+ isExistTpaAssembly = true;
+ break;
+ }
+ }
+ if (isExistTpaAssembly) break;
+ }
+ if (!isExistTpaAssembly) {
+ for (auto& assembly : assemblies.getMemberNames()) {
+ std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
+ parserData.push_back(nuget + ":" + assemblyName);
+ _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str());
+ }
+ }
+ }
+ }
+ }
+ }
+ appDependencies.clear();
+ ifs.close();
+ }
+ }
+ } catch (const Json::LogicError& error) {
+ _ERR("Failed to parse Json: %s", error.what());
+ }
+ tpaAssemblies.clear();
+ return parserData;
+}
int main(int argc, char* argv[])
{
if (initializePathManager(std::string(), std::string(), std::string())) {
- fprintf(stderr, "Fail to initialize PathManager");
+ fprintf(stderr, "Fail to initialize PathManager\n");
return -1;
}
* limitations under the License.
*/
+#include <algorithm>
+
#include "db_manager.h"
#include "log.h"
+#include "tac_common.h"
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
+static int dbIntegrityCheckCb(void *user_data, int argc, char **argv, char **not_used)
+{
+ 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") {
+ *is_db_corrupted = true;
+ _ERR("DB integrity check failed");
+ return -1;
+ }
+ _INFO("DB integrity result : %s", argv[0]);
+ return 0;
+}
+
sqlite3* dbCreate(std::string path)
{
sqlite3 *sqlite = NULL;
+ bool is_db_corrupted = false;
int ret = sqlite3_open(path.c_str(), &sqlite);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d] : path [%s]", ret, path.c_str());
- return NULL;
+ _INFO("DB file is corrupted, start to recover corrupted db");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite error : [%d, %s]", ret, path.c_str());
+ return NULL;
+ }
+ return dbCreate(path);
}
ret = sqlite3_exec(sqlite, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d]", ret);
- return NULL;
+ _ERR("Sqlite error : [%d, %s]", ret, path.c_str());
+ sqlite3_close(sqlite);
+ sqlite = NULL;
+ return sqlite;
}
ret = sqlite3_exec(sqlite, CREATE_TAC_DB_TABLE, NULL, NULL, NULL);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d] : path [%s]", ret, path.c_str());
- return NULL;
+ _ERR("Sqlite error : [%d, %s]", ret, path.c_str());
+ sqlite3_close(sqlite);
+ sqlite = NULL;
+ return sqlite;
+ }
+ ret = sqlite3_exec(sqlite, "PRAGMA integrity_check", dbIntegrityCheckCb, &is_db_corrupted, NULL);
+ if (ret == SQLITE_CORRUPT || is_db_corrupted) {
+ _INFO("DB file is corrupted, start to recover corrupted db");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite error : [%d, %s]", ret, path.c_str());
+ sqlite3_close(sqlite);
+ sqlite = NULL;
+ return sqlite;
+ }
+ return dbCreate(path);
}
return sqlite;
}
-bool dbOpen(sqlite3 *tac_db, std::string path)
+sqlite3* dbOpen(std::string path)
{
- if (!tac_db) {
- int ret = sqlite3_open(path.c_str(), &tac_db);
- if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d] : path [%s]", ret, path.c_str());
- return false;
+ sqlite3 *sqlite = NULL;
+ bool is_db_corrupted = false;
+ int ret = sqlite3_open(path.c_str(), &sqlite);
+ if (ret != SQLITE_OK) {
+ _INFO("DB file is corrupted, start to recover corrupted db");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite error : [%d, %s]", ret, path.c_str());
+ return NULL;
+ }
+ return dbOpen(path);
+ }
+ ret = sqlite3_exec(sqlite, "PRAGMA integrity_check", dbIntegrityCheckCb, &is_db_corrupted, NULL);
+ if (ret == SQLITE_CORRUPT || is_db_corrupted) {
+ _INFO("DB file is corrupted, start to recover corrupted db");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite error : [%d, %s]", ret, path.c_str());
+ sqlite3_close(sqlite);
+ sqlite = NULL;
+ return sqlite;
}
+ return dbOpen(path);
}
- return true;
+ return sqlite;
}
void dbFinalize(sqlite3_stmt *stmt)
bool dbUpdate(sqlite3 *tac_db, std::string path, std::string query)
{
sqlite3_stmt *stmt = NULL;
- if (!dbOpen(tac_db, path)) {
- return false;
- }
int ret = sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
ret = sqlite3_prepare(tac_db, query.c_str(), QUERY_MAX_LEN , &stmt, NULL);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%s, %s]", query.c_str(), sqlite3_errmsg(tac_db));
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbClose(tac_db);
return false;
}
ret = sqlite3_step(stmt);
if (ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d]", ret);
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbFinalize(stmt);
dbClose(tac_db);
return false;
bool dbInsert(sqlite3 *tac_db, std::string path, std::string query)
{
sqlite3_stmt *stmt = NULL;
- if (!dbOpen(tac_db, path)) {
- return false;
- }
int ret = sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
ret = sqlite3_prepare(tac_db, query.c_str(), QUERY_MAX_LEN , &stmt, NULL);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%s, %s]", query.c_str(), sqlite3_errmsg(tac_db));
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbClose(tac_db);
return false;
}
ret = sqlite3_step(stmt);
if (ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d]", ret);
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbFinalize(stmt);
dbClose(tac_db);
return false;
std::vector<std::string> updateDB;
sqlite3_stmt* stmt = NULL;
const char* str = NULL;
- if (!dbOpen(tac_db, path)) {
- return updateDB;
- }
int ret = sqlite3_prepare_v2(tac_db, query.c_str(), strlen(query.c_str()), &stmt, NULL);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%s, %s]", query.c_str(), sqlite3_errmsg(tac_db));
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbClose(tac_db);
return updateDB;
}
bool dbDelete(sqlite3 *tac_db, std::string path, std::string query)
{
sqlite3_stmt *stmt = NULL;
- if (!dbOpen(tac_db, path)) {
- return false;
- }
int ret = sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
ret = sqlite3_prepare(tac_db, query.c_str(), QUERY_MAX_LEN , &stmt, NULL);
if (ret != SQLITE_OK) {
- _ERR("Sqlite error : [%s, %s]", query.c_str(), sqlite3_errmsg(tac_db));
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbClose(tac_db);
return false;
}
ret = sqlite3_step(stmt);
if (ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_OK) {
- _ERR("Sqlite error : [%d]", ret);
+ _ERR("Sqlite error : [%d, %s]", ret, sqlite3_errmsg(tac_db));
dbFinalize(stmt);
dbClose(tac_db);
return false;
#include <pkgmgr-info.h>
#include <pkgmgr_installer_info.h>
#include <sys/smack.h>
-#include <json/json.h>
#include <cstdlib>
#include <cstring>
}
return true;
}
-
-//Parser the .deps.json file to get nuget information.
-std::vector<std::string> depsJsonParser(std::string rootPath, std::string execName, std::string tpaList)
-{
- std::vector<std::string> tpaAssemblies;
- splitPath(tpaList, tpaAssemblies);
-
- std::vector<std::string> parserData;
- std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
- std::string depsJsonPath = concatPath(rootPath, depsJsonName);
- try {
- if (bf::exists(depsJsonPath)) {
- std::ifstream ifs(depsJsonPath);
- Json::CharReaderBuilder reader;
- Json::Value root;
- std::string error;
- if (ifs.is_open()) {
- if (!Json::parseFromStream(reader, ifs, &root, &error)) {
- _ERR("Failed to parse of deps.json");
- ifs.close();
- tpaAssemblies.clear();
- return parserData;
- }
- const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
- const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
- std::vector<std::string> appDependencies;
- for (auto& nuget : nugetPackages.getMemberNames()) {
- if (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) {
- const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
- if (assemblies != Json::nullValue) {
- const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
- for (auto& dependency : dependencies.getMemberNames()) {
- appDependencies.push_back(dependency);
- }
- }
- }
- }
- for (auto& nuget : nugetPackages.getMemberNames()) {
- //Skip the nuget package related to Tizen
- 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) {
- const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
- if (assemblies != Json::nullValue) {
- const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
- bool hasDependency = false;
- for (auto& dependency : dependencies.getMemberNames()) {
- //Skip the nugget package that is dependent on another nuget package
- if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
- strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) == NULL) {
- hasDependency = true;
- for (auto& ad : appDependencies) {
- if (!strcmp(ad.c_str(), dependency.c_str())) {
- hasDependency = true;
- break;
- } else {
- hasDependency = false;
- }
- }
- if (hasDependency) break;
- }
- }
- if (!hasDependency) {
- bool isExistTpaAssembly = false;
- for (auto& assembly : assemblies.getMemberNames()) {
- std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
- //Skip the assembly present in the TPA list
- for (auto& tpa : tpaAssemblies) {
- if (!strcmp(replaceAll(tpa, ".ni.dll", ".dll").c_str(), assembly.c_str())) {
- isExistTpaAssembly = true;
- break;
- }
- }
- if (isExistTpaAssembly) break;
- }
- if (!isExistTpaAssembly) {
- for (auto& assembly : assemblies.getMemberNames()) {
- std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
- parserData.push_back(nuget + ":" + assemblyName);
- _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str());
- }
- }
- }
- }
- }
- }
- appDependencies.clear();
- ifs.close();
- }
- }
- } catch (const Json::LogicError& error) {
- _ERR("Failed to parse Json: %s", error.what());
- }
- tpaAssemblies.clear();
- return parserData;
-}
\ No newline at end of file
%{_bindir}/dotnet-launcher
%{_libdir}/libdotnet_launcher_util.so
%{_libdir}/libni_common.so
+%{_libdir}/libtac_common.so
/etc/tmpfiles.d/%{name}.conf
/usr/share/parser-plugins/dotnet-launcher.info
%{_framework_dir}/Tizen.Init.dll
%{_includedir}/coreclr_host.h
%{_libdir}/libdotnet_launcher_util.so
%{_libdir}/libni_common.so
+%{_libdir}/libtac_common.so
%{_libdir}/pkgconfig/dotnet-launcher.pc