From 33b4aa2fcbb716d081fc13ac6855fc53bd343532 Mon Sep 17 00:00:00 2001 From: "j-h.choi" Date: Thu, 18 Jan 2024 15:40:47 +0900 Subject: [PATCH] [Refactoring] Code cleanup and remove duplicate methods Change-Id: I6c65e5108b0110a51b5f9d60e34779d7d4f300ef --- NativeLauncher/CMakeLists.txt | 8 +- NativeLauncher/hydra/hydra_main.cc | 4 +- NativeLauncher/inc/multi_target_resolver.h | 3 +- NativeLauncher/inc/r2r_checker.h | 10 +- NativeLauncher/inc/utils.h | 7 - .../installer-plugin/dotnet_apptype_plugin.cc | 2 +- .../installer-plugin/prefer_dotnet_aot_plugin.cc | 4 +- NativeLauncher/launcher/exec/corerun.cc | 3 +- NativeLauncher/launcher/lib/core_runtime.cc | 4 +- NativeLauncher/tool/dotnettool.cc | 5 +- NativeLauncher/tool/multi_target_resolver.cc | 13 +- NativeLauncher/tool/ni_common.cc | 147 +++++++-------------- NativeLauncher/tool/r2r_checker.cc | 10 +- NativeLauncher/tool/tac_common.cc | 7 +- NativeLauncher/tool/tac_installer.cc | 16 +-- NativeLauncher/util/plugin_manager.cc | 2 +- NativeLauncher/util/utils.cc | 16 +-- 17 files changed, 103 insertions(+), 158 deletions(-) diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 350d373..d89bba3 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -111,12 +111,14 @@ INCLUDE_DIRECTORIES(inc launcher util) SET(DOTNET_LAUNCHER_UTIL "dotnet_launcher_util") SET(${DOTNET_LAUNCHER_UTIL}_SOURCE_FILES - util/utils.cc - util/plugin_manager.cc + tool/r2r_checker.cc util/path_manager.cc + util/plugin_manager.cc + util/utils.cc ) ADD_LIBRARY(${DOTNET_LAUNCHER_UTIL} SHARED ${${DOTNET_LAUNCHER_UTIL}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER_UTIL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB}) +TARGET_INCLUDE_DIRECTORIES(${DOTNET_LAUNCHER_UTIL} PRIVATE ${RUNTIME_DIR}/src/ ${RUNTIME_DIR}/src/pal ${RUNTIME_DIR}/src/pal/inc ${RUNTIME_DIR}/src/pal/inc/rt) TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER_UTIL} ${${PROJECT_NAME}_LDFLAGS} "-ldl" boost_filesystem boost_system) SET(DOTNET_LAUNCHER_CORE "dotnet_launcher_core") @@ -192,11 +194,9 @@ TARGET_LINK_LIBRARIES(${TAC_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER SET(NI_COMMON "ni_common") SET(${NI_COMMON}_SOURCE_FILES tool/ni_common.cc - tool/r2r_checker.cc ) ADD_LIBRARY(${NI_COMMON} SHARED ${${NI_COMMON}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${NI_COMMON} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB}) -TARGET_INCLUDE_DIRECTORIES(${NI_COMMON} PRIVATE ${RUNTIME_DIR}/src/ ${RUNTIME_DIR}/src/pal ${RUNTIME_DIR}/src/pal/inc ${RUNTIME_DIR}/src/pal/inc/rt) TARGET_LINK_LIBRARIES(${NI_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${TAC_COMMON}) SET(PROFILE_COMMON "profile_common") diff --git a/NativeLauncher/hydra/hydra_main.cc b/NativeLauncher/hydra/hydra_main.cc index b14f1ef..7ced0a3 100644 --- a/NativeLauncher/hydra/hydra_main.cc +++ b/NativeLauncher/hydra/hydra_main.cc @@ -31,8 +31,8 @@ #include "log.h" #include "launcher_env.h" -const char* __coreclr_lib = "/usr/share/dotnet.tizen/netcoreapp/libcoreclr.so"; -const char* __dotnet_loader = "/usr/bin/dotnet-loader"; +static const char* __coreclr_lib = "/usr/share/dotnet.tizen/netcoreapp/libcoreclr.so"; +static const char* __dotnet_loader = "/usr/bin/dotnet-loader"; typedef int (*coreclr_preload_assembly_ptr)(const char* assemblyPath); typedef int (*launcher_real_main_ptr)(int argc, char *argv[]); diff --git a/NativeLauncher/inc/multi_target_resolver.h b/NativeLauncher/inc/multi_target_resolver.h index 380fcd0..9c57a77 100644 --- a/NativeLauncher/inc/multi_target_resolver.h +++ b/NativeLauncher/inc/multi_target_resolver.h @@ -27,8 +27,7 @@ int resolvePlatformSpecificFiles(const std::string& appRootPath); /** * @brief resolve bin/runtimes directory if exist. - * @return 0 if success, otherwise -1 */ -int resolveAllApps(); +void resolveAllApps(); #endif /* __MULTI_TAEGET_RESOLVER_H__ */ diff --git a/NativeLauncher/inc/r2r_checker.h b/NativeLauncher/inc/r2r_checker.h index 4694eff..ef10571 100644 --- a/NativeLauncher/inc/r2r_checker.h +++ b/NativeLauncher/inc/r2r_checker.h @@ -19,7 +19,13 @@ #include -bool isR2RImage(std::string fileName); -unsigned int getSizeOfImage(std::string fileName); +/** + * @brief check the file is r2r image or not. + * @param[in] file name + * @return return true when the file is r2r image. + */ +bool isR2RImage(const std::string& fileName); + +unsigned int getSizeOfImage(const std::string& fileName); #endif /* __R2R_CHECKER_H__ */ diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 927b213..524264e 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -165,13 +165,6 @@ bool isDirectory(const std::string& path); bool isManagedAssembly(const std::string& filePath); /** - * @brief check the file is native image or not. - * @param[in] file path - * @return return true when the file is native image. - */ -bool isNativeImage(const std::string& filePath); - -/** * @brief Resolve assembly files from directories and append their paths to the given list. * @remark If a native image exists for an assembly in the same directory, it will be used. * If multiple assemblies of the same name exist, the first one will be used. diff --git a/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc b/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc index 48e0ed3..0cff386 100644 --- a/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc +++ b/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc @@ -30,7 +30,7 @@ typedef struct _xmlDoc xmlDoc; typedef xmlDoc* xmlDocPtr; -bool pluginInstalled = false; +static bool pluginInstalled = false; extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId) { diff --git a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc index 91928a7..840a40b 100644 --- a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc +++ b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc @@ -30,8 +30,8 @@ #endif #define LOG_TAG "DOTNET_INSTALLER_PLUGIN" -bool aotPluginInstalled = false; -bool aotPluginFinished = false; +static bool aotPluginInstalled = false; +static bool aotPluginFinished = false; extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list) { diff --git a/NativeLauncher/launcher/exec/corerun.cc b/NativeLauncher/launcher/exec/corerun.cc index 81fdb0c..820679b 100644 --- a/NativeLauncher/launcher/exec/corerun.cc +++ b/NativeLauncher/launcher/exec/corerun.cc @@ -19,6 +19,7 @@ #include "coreclr_host.h" #include "log.h" #include "utils.h" +#include "r2r_checker.h" static const char* CLR_PATH = "/usr/share/dotnet.tizen/netcoreapp"; static const char* TOOL_PATH = "/home/owner/share/.dotnet/tools"; @@ -102,7 +103,7 @@ int main(int argc, const char* argv[]) { _SERR("Unknown option %s.", argv[0]); DisplayUsage(); return -1; - } else if (isManagedAssembly(arg) || isNativeImage(arg)) { + } else if (isManagedAssembly(arg) || isR2RImage(arg)) { if (!isFile(arg)) { _SERR("The specified file does not exist."); return -1; diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index ba874aa..d0b0704 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -97,8 +97,8 @@ static void setEnvFromFile() #define _unused(x) ((void)(x)) -struct sigaction sig_abrt_new; -struct sigaction sig_abrt_old; +static struct sigaction sig_abrt_new; +static struct sigaction sig_abrt_old; static bool checkOnSigabrt = false; static bool checkOnTerminate = false; diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc index 628124c..eac0f2a 100644 --- a/NativeLauncher/tool/dotnettool.cc +++ b/NativeLauncher/tool/dotnettool.cc @@ -401,10 +401,7 @@ int main(int argc, char* argv[]) } //sh-3.2# dotnettool --resolve-all-app else if (cmd == "--resolve-all-app") { - int ret = resolveAllApps(); - if (ret != 0) { - _SERR("Failed to remove unused multi-targeting files"); - } + resolveAllApps(); } //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ... else if (cmd == "--rm-app-profile") { diff --git a/NativeLauncher/tool/multi_target_resolver.cc b/NativeLauncher/tool/multi_target_resolver.cc index 264dc6d..0f94ebb 100644 --- a/NativeLauncher/tool/multi_target_resolver.cc +++ b/NativeLauncher/tool/multi_target_resolver.cc @@ -202,28 +202,29 @@ static int appResolveCb(pkgmgrinfo_appinfo_h handle, void *user_data) return 0; } -int resolveAllApps() +void resolveAllApps() { int ret = 0; pkgmgrinfo_appinfo_filter_h handle; ret = pkgmgrinfo_appinfo_filter_create(&handle); if (ret != PMINFO_R_OK) { - return -1; + _SERR("Failed to create pkgmgrinfo"); + return; } ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, "dotnet"); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_filter_destroy(handle); - return -1; + _SERR("Failed to add pkgmgrinfo filter app type"); + return; } ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, appResolveCb, NULL); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_filter_destroy(handle); - return -1; + _SERR("Failed to remove unused multi-targeting files"); + return; } pkgmgrinfo_appinfo_filter_destroy(handle); - - return 0; } diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index bc0a466..08d9d6f 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -230,8 +230,35 @@ static bool createDirsAndCopyOwnerShip(std::string& target_path, const std::stri return true; } -static std::string getNIFilePath(const std::string& dllPath) +static std::string getNIFilePath(const std::string& absDllPath, NIOption* opt) { + std::string dllPath = absDllPath; + if (opt->flags & NI_FLAGS_APPNI) { + std::string niDirPath; + std::string niTmpDirPath; + std::string prevPath; + + prevPath = getBaseName(absDllPath); + niDirPath = concatPath(prevPath, APP_NI_SUB_DIR); + niTmpDirPath = concatPath(prevPath, APP_NI_SUB_TMP_DIR); + + if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) { + niTmpDirPath = replaceAll(niTmpDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); + niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); + _INFO("App is installed in RO area. Change NI path to RW area(%s).", niTmpDirPath.c_str()); + } + + if (!isDirectory(niDirPath)) { + if (!createDirsAndCopyOwnerShip(niTmpDirPath, prevPath)) { + niTmpDirPath = prevPath; + _SERR("fail to create dir (%s)", niTmpDirPath.c_str()); + } + dllPath = concatPath(niTmpDirPath, getFileName(absDllPath)); + } else { + dllPath = concatPath(niDirPath, getFileName(absDllPath)); + } + } + size_t index = dllPath.find_last_of("."); if (index == std::string::npos) { _SERR("File doesnot contain extension. fail to get NI file name"); @@ -247,33 +274,9 @@ static std::string getNIFilePath(const std::string& dllPath) return niPath; } -static std::string getAppNIFilePath(const std::string& absDllPath, NIOption* opt) +static bool checkNIExistence(const std::string& absDllPath, NIOption* opt) { - std::string niDirPath; - std::string prevPath; - - prevPath = getBaseName(absDllPath); - niDirPath = concatPath(prevPath, APP_NI_SUB_TMP_DIR); - - if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) { - niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); - _SERR("App is installed in RO area. Change NI path to RW area(%s).", niDirPath.c_str()); - _ERR("App is installed in RO area. Change NI path to RW area(%s).", niDirPath.c_str()); - } - - if (!isDirectory(niDirPath)) { - if (!createDirsAndCopyOwnerShip(niDirPath, prevPath)) { - niDirPath = prevPath; - _SERR("fail to create dir (%s)", niDirPath.c_str()); - } - } - - return getNIFilePath(concatPath(niDirPath, getFileName(absDllPath))); -} - -static bool checkNIExistence(const std::string& absDllPath) -{ - std::string absNIPath = getNIFilePath(absDllPath); + std::string absNIPath = getNIFilePath(absDllPath, opt); if (absNIPath.empty()) { return false; } @@ -291,25 +294,11 @@ static bool checkNIExistence(const std::string& absDllPath) return false; } -static bool checkAppNIExistence(const std::string& absDllPath, NIOption* opt) -{ - std::string absNIPath = getAppNIFilePath(absDllPath, opt); - if (absNIPath.empty()) { - return false; - } - - if (isFile(absNIPath)) { - return true; - } - - return false; -} - static bool checkDllExistInDir(const std::string& path) { bool ret = false; auto func = [&ret](const std::string& f_path, const std::string& f_name) { - if (isManagedAssembly(f_name) || isNativeImage(f_name)) { + if (isManagedAssembly(f_name) || isR2RImage(f_name)) { ret = true; } }; @@ -320,41 +309,18 @@ static bool checkDllExistInDir(const std::string& path) } /* - * Get the list of managed files in the specific directory - * Absolute paths of managed files are stored at the result list. - * If native image already exist in the same directory, managed file is ignored. - */ -static ni_error_e getTargetDllList(const std::string& path, std::vector& fileList) -{ - if (!isDirectory(path)) { - return NI_ERROR_INVALID_PARAMETER; - } - - auto func = [&fileList](const std::string& f_path, const std::string& f_name) { - if (isManagedAssembly(f_path) && !checkNIExistence(f_path)) { - fileList.push_back(getAbsolutePath(f_path)); - } - }; - - scanFilesInDirectory(path, func, 0); - - return NI_ERROR_NONE; -} - -/* - * Get the list of managed files in the specific directory of Application + * Get the list of managed files in the specific directory (of Application) * Absolute paths of managed files are stored at the result list. - * If native image already exist in the .native_image directory, managed file is ignored. - * + * If native image already exist in the (same / .native_image) directory, managed file is ignored. */ -static ni_error_e getAppTargetDllList(const std::string& path, std::vector& fileList, NIOption *opt) +static ni_error_e getTargetDllList(const std::string& path, std::vector& fileList, NIOption *opt) { if (!isDirectory(path)) { return NI_ERROR_INVALID_PARAMETER; } auto func = [&fileList, opt](const std::string& f_path, const std::string& f_name) { - if (isManagedAssembly(f_path) && !checkAppNIExistence(f_path, opt)) { + if (isManagedAssembly(f_path) && !checkNIExistence(f_path, opt)) { fileList.push_back(getAbsolutePath(f_path)); } }; @@ -482,7 +448,7 @@ static ni_error_e crossgen2PostAction(const std::string& dllPath, const std::str // if AppNI then move ni.dll file to .native_image and copy pdb to .native_image if (opt->flags & NI_FLAGS_APPNI) { - outFile = getAppNIFilePath(dllPath, opt); + outFile = getNIFilePath(dllPath, opt); makePdbSymlinkForNI(dllPath, outFile); if (opt->flags & NI_FLAGS_INPUT_BUBBLE && opt->flags & NI_FLAGS_NO_PIPELINE) { @@ -581,11 +547,8 @@ static ni_error_e crossgen2NoPipeLine(const std::vector& dllList, c { for (auto& dllPath : dllList) { std::string niPath; - if (opt->flags & NI_FLAGS_APPNI) { - niPath = getAppNIFilePath(dllPath, opt); - } else { - niPath = getNIFilePath(dllPath); - } + niPath = getNIFilePath(dllPath, opt); + #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT uintptr_t baseAddr = 0; if (isTPADll(dllPath)) { @@ -721,6 +684,8 @@ static void renameAppNITmpPath(NIOption* opt) if (isDirectory(niTmpPath)) { if (rename(niTmpPath.c_str(), niPath.c_str())) { _SERR("Fail to rename from .native_image_tmp to .native_image"); + } else { + _SOUT("Success to rename from %s to %s", niTmpPath.c_str(), niPath.c_str()); } } } @@ -808,12 +773,7 @@ static ni_error_e doAOTList(std::vector& dllList, const std::string if (opt->flags & NI_FLAGS_INPUT_BUBBLE) { for (auto &dll : dllList) { std::string tmpFile; - std::string niFile; - if (opt->flags & NI_FLAGS_APPNI) { - niFile = getAppNIFilePath(dll, opt); - } else { - niFile = getNIFilePath(dll); - } + std::string niFile = getNIFilePath(dll, opt); tmpFile = niFile + ".tmp"; if (exist(tmpFile)) { @@ -837,16 +797,16 @@ static ni_error_e doAOTFile(const std::string& dllFile, const std::string& refPa return NI_ERROR_NO_SUCH_FILE; } + if (checkNIExistence(dllFile, opt)) { + _SERR("Native image file is already exist : %s", dllFile.c_str()); + return NI_ERROR_ALREADY_EXIST; + } + if (!isManagedAssembly(dllFile)) { _SERR("Failed. Input parameter is not managed dll (%s)\n", dllFile.c_str()); return NI_ERROR_INVALID_PARAMETER; } - if (checkNIExistence(dllFile)) { - _SERR("Native image file is already exist : %s", dllFile.c_str()); - return NI_ERROR_ALREADY_EXIST; - } - std::vector dllList; dllList.push_back(getAbsolutePath(dllFile)); return doAOTList(dllList, refPaths, opt); @@ -991,7 +951,7 @@ ni_error_e createNIUnderTAC(const std::string& targetPath, const std::string& re // get managed file list from targetPath std::vector dllList; - ret = getTargetDllList(targetPath, dllList); + ret = getTargetDllList(targetPath, dllList, opt); if (ret != NI_ERROR_NONE) { return ret; } @@ -1000,10 +960,10 @@ ni_error_e createNIUnderTAC(const std::string& targetPath, const std::string& re std::vector niList; for (auto &dll : dllList) { - if (!checkNIExistence(dll)) { + if (!checkNIExistence(dll, opt)) { needNIList.push_back(dll); } - niList.push_back(getNIFilePath(dll)); + niList.push_back(getNIFilePath(dll, opt)); } if (!needNIList.empty()) { @@ -1063,13 +1023,8 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, NIOption* opt) if (ret != NI_ERROR_NONE) { return ret; } - } else if (opt->flags & NI_FLAGS_APPNI) { - ret = getAppTargetDllList(path, fileList, opt); - if (ret != NI_ERROR_NONE) { - return ret; - } } else { - ret = getTargetDllList(path, fileList); + ret = getTargetDllList(path, fileList, opt); if (ret != NI_ERROR_NONE) { return ret; } @@ -1153,7 +1108,7 @@ void removeNIPlatform() void removeNIUnderDirs(const std::string& rootPaths) { auto convert = [](const std::string& path, const std::string& filename) { - if (isNativeImage(path)) { + if (isR2RImage(path)) { std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll"); if (exist(assemblyPath)) { if (remove(path.c_str())) { diff --git a/NativeLauncher/tool/r2r_checker.cc b/NativeLauncher/tool/r2r_checker.cc index bf8d2dc..06ef6e4 100644 --- a/NativeLauncher/tool/r2r_checker.cc +++ b/NativeLauncher/tool/r2r_checker.cc @@ -110,7 +110,6 @@ static bool hasValidR2RHeader(void* pAddr) { IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr); if (!pNTHeaders) { - _SERR("Invalid NT Header"); return false; } @@ -141,12 +140,11 @@ static bool hasValidR2RHeader(void* pAddr) return false; } -bool isR2RImage(std::string fileName) +bool isR2RImage(const std::string& fileName) { int fd; struct stat sb; if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) { - _SERR("File Not Found: %s", fileName.c_str()); return false; } @@ -157,7 +155,6 @@ bool isR2RImage(std::string fileName) void* pAddr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (pAddr == MAP_FAILED) { - _SERR("Fail to Map File: %s", fileName.c_str()); close(fd); return false; } @@ -169,12 +166,11 @@ bool isR2RImage(std::string fileName) return ret; } -unsigned int getSizeOfImage(std::string fileName) +unsigned int getSizeOfImage(const std::string& fileName) { int fd; struct stat sb; if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) { - _SERR("File Not Found: %s", fileName.c_str()); return 0; } @@ -185,14 +181,12 @@ unsigned int getSizeOfImage(std::string fileName) void* pAddr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (pAddr == MAP_FAILED) { - _SERR("Fail to Map File: %s", fileName.c_str()); close(fd); return 0; } IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr); if (!pNTHeaders) { - _SERR("Invalid NT Header"); munmap(pAddr, sb.st_size); close(fd); return 0; diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 93462ec..94ff439 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -23,6 +23,7 @@ #include "utils.h" #include "tac_common.h" #include "db_manager.h" +#include "r2r_checker.h" #ifdef LOG_TAG #undef LOG_TAG @@ -38,8 +39,8 @@ static const char* __READ_ONLY_APP_UPDATE_DIR = __STR(READ_ONLY_APP_UPDATE_DIR); static sqlite3 *tac_db = NULL; static sqlite3 *tlc_db = NULL; -std::vector restore_nuget; -std::vector restore_library; +static std::vector restore_nuget; +static std::vector restore_library; static void cleanupDirectory() { @@ -223,7 +224,7 @@ tac_error_e disableTACPackage(const std::string& pkgId) std::string fileName = symlinkAssembly.path().filename().string(); if (isSymlinkFile(symPath)) { std::string originPath = bf::read_symlink(symPath).string(); - if (!isNativeImage(symPath)) { + if (!isR2RImage(symPath)) { std::string dllPath = concatPath(binDir, fileName); if (!copyFile(originPath, dllPath)) { _SERR("Failed to copy of %s", dllPath.c_str()); diff --git a/NativeLauncher/tool/tac_installer.cc b/NativeLauncher/tool/tac_installer.cc index c01a616..6bf9b57 100644 --- a/NativeLauncher/tool/tac_installer.cc +++ b/NativeLauncher/tool/tac_installer.cc @@ -40,16 +40,16 @@ static const char* __DOTNET_DIR = __STR(DOTNET_DIR); #undef __STR #undef __XSTR -std::vector nugetPackagesAssembliesSha; -std::vector tacDB; -std::vector createDirectories; -std::vector createLibraries; -std::vector updateTac; -tac_state tacState = TAC_STATE_NONE; +static std::vector nugetPackagesAssembliesSha; +static std::vector tacDB; +static std::vector createDirectories; +static std::vector createLibraries; +static std::vector updateTac; +static tac_state tacState = TAC_STATE_NONE; static sqlite3 *tac_db = NULL; static sqlite3 *tlc_db = NULL; -bool tacPluginInstalled = false; -bool tacPluginFinished = false; +static bool tacPluginInstalled = false; +static bool tacPluginFinished = false; static void createSHA256Info(std::string sha256Info, std::string nugetPackage) { diff --git a/NativeLauncher/util/plugin_manager.cc b/NativeLauncher/util/plugin_manager.cc index 4fcd787..472415d 100644 --- a/NativeLauncher/util/plugin_manager.cc +++ b/NativeLauncher/util/plugin_manager.cc @@ -22,7 +22,7 @@ static PluginFunc* __pluginFunc = NULL; static void* __pluginLib; -bool initializedPluginManager = false; +static bool initializedPluginManager = false; int initializePluginManager(const char* appType) { diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 9f34fb4..37ba52e 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -43,6 +43,7 @@ #include "log.h" #include "utils.h" #include "path_manager.h" +#include "r2r_checker.h" static bool iCompare(const std::string& a, int aOffset, const std::string& b, int bOffset, int length) { @@ -55,12 +56,7 @@ static bool iCompare(const std::string& a, int aOffset, const std::string& b, in bool isManagedAssembly(const std::string& fileName) { - return iCompare(fileName, fileName.size()-4, ".dll", 0, 4) && !isNativeImage(fileName); -} - -bool isNativeImage(const std::string& fileName) -{ - return iCompare(fileName, fileName.size()-7, ".ni", 0, 3); + return iCompare(fileName, fileName.size()-4, ".dll", 0, 4) && !isR2RImage(fileName); } std::string concatPath(const std::string& path1, const std::string& path2) @@ -82,7 +78,9 @@ void splitPath(const std::string& path, std::vector& out) std::string token; while (std::getline(ss, token, ':')) { - out.push_back(token); + if (token != "") { + out.push_back(token); + } } } @@ -340,13 +338,13 @@ void addAssembliesFromDirectories(const std::vector& directories, s std::unordered_map assemPaths; auto reader = [&assems, &assemPaths](const std::string& path, const std::string& filename) { - if (isManagedAssembly(filename) || isNativeImage(filename)) { + if (isManagedAssembly(filename) || isR2RImage(filename)) { std::string assem = getAssemblyNameFromPath(filename); if (assemPaths.count(assem) == 0) { assems.push_back(assem); assemPaths[assem] = path; - } else if (isManagedAssembly(assemPaths[assem]) && isNativeImage(filename)) { + } else if (isManagedAssembly(assemPaths[assem]) && isR2RImage(filename)) { // Update only if a native image is found in the same directory. // For example, if we have two directories = { X, Y } where X contains A.dll and // Y contains both A.dll and A.ni.dll, always A.dll in X will be used. -- 2.7.4