From: 이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 11 Jun 2020 01:11:35 +0000 (+0900) Subject: Minor readability fix (#244) X-Git-Tag: submit/tizen/20200622.225420~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a0d37e61e62ffcbc6652030d8db4ed60e76ce36;p=platform%2Fcore%2Fdotnet%2Flauncher.git Minor readability fix (#244) Change-Id: I5fcf45f8a9809e832bc0ebf622c8167eb83f0ba1 --- diff --git a/NativeLauncher/hydra/hydra_main.cc b/NativeLauncher/hydra/hydra_main.cc index b0e7671..5b59cf3 100644 --- a/NativeLauncher/hydra/hydra_main.cc +++ b/NativeLauncher/hydra/hydra_main.cc @@ -37,7 +37,7 @@ 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[], const char* mode); -static std::string absolutePath(const std::string& path) +static std::string getAbsolutePath(const std::string& path) { std::string absPath; char *realPath = realpath(path.c_str(), NULL); @@ -49,7 +49,7 @@ static std::string absolutePath(const std::string& path) return absPath; } -static bool isFileExist(const std::string& path) +static bool isFile(const std::string& path) { struct stat sb; return stat(path.c_str(), &sb) == 0; @@ -78,13 +78,13 @@ static std::string findDllPath(const std::string& filename) // check whether the target file exist under netcoreapp directory result = netcoreappDir + filename; - if (isFileExist(result)) { + if (isFile(result)) { return result; } // check whether the target file exist under framework directory result = frameworkDir + filename; - if (isFileExist(result)) { + if (isFile(result)) { return result; } @@ -168,7 +168,7 @@ static void preloadAssemblies() // check whether the target file exist under netcoreapp directory std::string path = findDllPath(in_line); if (!path.empty()) { - int st = preloadAssembly(absolutePath(path).c_str()); + int st = preloadAssembly(getAbsolutePath(path).c_str()); if (st != 0) { _ERR("preload of %s failed! (0x%08x)", path.c_str(), st); } else { diff --git a/NativeLauncher/inc/ni_common.h b/NativeLauncher/inc/ni_common.h index 9fcd321..4107e87 100644 --- a/NativeLauncher/inc/ni_common.h +++ b/NativeLauncher/inc/ni_common.h @@ -48,18 +48,18 @@ typedef enum { /** * @brief : structure which contains base directory info */ -typedef struct NiCommonOption { +typedef struct NICommonOption { std::string runtimeDir; /**< .NETCore Runtime directory */ std::string tizenFXDir; /**< TizenFX directory */ std::string extraDirs; /**< ":" seperated directories which can be set by plugins */ -} NiCommonOption; +} NICommonOption; /** * @brief initialize NICommon * @param[i] options base directory info * @return ni_error_e 0 on success, otherwise a negative error value */ -ni_error_e initNICommon(NiCommonOption* option); +ni_error_e initNICommon(NICommonOption* option); /** * @brief finalize NICommon @@ -72,7 +72,7 @@ void finalizeNICommon(); * @param[i] flags additional flags for the image generator * @return ni_error_e */ -ni_error_e createNiPlatform(DWORD flags); +ni_error_e createNIPlatform(DWORD flags); /** * @brief create a native image for a single DLL @@ -80,7 +80,7 @@ ni_error_e createNiPlatform(DWORD flags); * @param[i] flags additional flags for the image generator * @return ni_error_e */ -ni_error_e createNiDll(const std::string& dllPath, DWORD flags); +ni_error_e createNIDll(const std::string& dllPath, DWORD flags); /** * @brief create native images for TAC DLLs @@ -88,7 +88,7 @@ ni_error_e createNiDll(const std::string& dllPath, DWORD flags); * @param[i] count length of rootPaths * @param[i] flags additional flags for the image generator */ -void createNiUnderTAC(const std::string rootPaths[], int count, DWORD flags); +void createNIUnderTAC(const std::string rootPaths[], int count, DWORD flags); /** * @brief creates a symbolic link file, the native image of TAC for specific package. @@ -105,7 +105,7 @@ ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags); * @param[i] flags additional flags for the image generator * @return ni_error_e */ -ni_error_e createNiUnderDirs(const std::string rootPaths[], int count, DWORD flags); +ni_error_e createNIUnderDirs(const std::string rootPaths[], int count, DWORD flags); /** * @brief create native images for all DLLs in a package @@ -113,7 +113,7 @@ ni_error_e createNiUnderDirs(const std::string rootPaths[], int count, DWORD fla * @param[i] flags additional flags for the image generator * @return ni_error_e */ -ni_error_e createNiUnderPkgRoot(const std::string& pkgId, DWORD flags); +ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags); /** * @brief create a native image for a single dll in a package @@ -122,26 +122,26 @@ ni_error_e createNiUnderPkgRoot(const std::string& pkgId, DWORD flags); * @param[i] flags additional flags for the image generator * @return ni_error_e */ -ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string& dllPath, DWORD flags); +ni_error_e createNIDllUnderPkgRoot(const std::string& pkgId, const std::string& dllPath, DWORD flags); /** * @brief remove platform native images (.NETCore + TizenFX) */ -void removeNiPlatform(); +void removeNIPlatform(); /** * @brief remove native images under directories * @param[i] rootPaths paths to directories * @param[i] count length of rootPaths */ -void removeNiUnderDirs(const std::string rootPaths[], int count); +void removeNIUnderDirs(const std::string rootPaths[], int count); /** * @brief remove native images of a package * @param[i] pkgId package ID * @return ni_error_e */ -ni_error_e removeNiUnderPkgRoot(const std::string& pkgId); +ni_error_e removeNIUnderPkgRoot(const std::string& pkgId); /** * @brief regenerate native images of all installed applications diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 90cc23d..ff06fa5 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -62,18 +62,18 @@ std::string readSelfPath(); std::string concatPath(const std::string& path1, const std::string& path2); /** - * @brief get absolute Path + * @brief get canonicalized absolute Path * @param[in] source path * return std::string result path */ -std::string absolutePath(const std::string& path); +std::string getAbsolutePath(const std::string& path); /** * @brief get the directory of file * @param[in] source path * return std::string result path */ -std::string baseName(const std::string& path); +std::string getBaseName(const std::string& path); /** * @brief replaces all matching substrings of the regular expression with a given replacement @@ -114,18 +114,18 @@ int getMetadataValue(std::string pkgId, std::string metadataKey, std::string& me void splitPath(const std::string& path, std::vector& out); /** - * @brief check file is exist + * @brief check file exists * @param[in] source path * @return bool */ -bool isFileExist(const std::string& path); +bool isFile(const std::string& path); /** - * @brief check directory is exist + * @brief check directory exists * @param[in] source path * @return bool */ -bool isDirectoryExist(const std::string& path); +bool isDirectory(const std::string& path); /** * @brief get file size diff --git a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc index 9e09ad1..b337820 100644 --- a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc +++ b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc @@ -67,13 +67,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app } if (mdValue) { - NiCommonOption option = {std::string(), std::string(), std::string()}; + NICommonOption option = {std::string(), std::string(), std::string()}; if (initNICommon(&option) < 0) { _ERR("Fail to initialize NI Common"); return -1; } - if (createNiUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) { + if (createNIUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) { _ERR("Failed to get root path from [%s]", pkgId); return -1; } else { @@ -100,19 +100,19 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app 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(createNiDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) { + std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + if (!bf::exists(originNIPath)) { + if(createNIDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) { _ERR("Failed to create NI file [%s]", 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); - _INFO("%s symbolic link file generated successfully.", setNiPath.c_str()); - if (lchown(setNiPath.c_str(), g_uid, g_gid)) { - _ERR("Failed to change owner of: %s", setNiPath.c_str()); + std::string setNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll"; + if (!bf::exists(setNIPath)) { + bf::create_symlink(originNIPath, setNIPath); + _INFO("%s symbolic link file generated successfully.", setNIPath.c_str()); + if (lchown(setNIPath.c_str(), g_uid, g_gid)) { + _ERR("Failed to change owner of: %s", setNIPath.c_str()); return -1; } } diff --git a/NativeLauncher/launcher/exec/corerun.cc b/NativeLauncher/launcher/exec/corerun.cc index 2ac5d63..da6ccb3 100644 --- a/NativeLauncher/launcher/exec/corerun.cc +++ b/NativeLauncher/launcher/exec/corerun.cc @@ -85,7 +85,7 @@ int main(int argc, const char* argv[]) { argc--; argv++; } else if (arg == "--additionalprobingpath" && argc > 1) { - additionalProbingPath = absolutePath(argv[1]); + additionalProbingPath = getAbsolutePath(argv[1]); argc--; argv++; } else if (arg == "--globalizationinvariant") { @@ -100,7 +100,7 @@ int main(int argc, const char* argv[]) { DisplayUsage(); return -1; } else if (isManagedAssembly(arg) || isNativeImage(arg)) { - if (!isFileExist(arg)) { + if (!isFile(arg)) { fprintf(stderr, "The specified file does not exist.\n"); return -1; } @@ -116,7 +116,7 @@ int main(int argc, const char* argv[]) { } else { managedAssemblyPath = toolDllsPath + "/dotnet-" + arg + ".dll"; - if (!isFileExist(managedAssemblyPath)) { + if (!isFile(managedAssemblyPath)) { fprintf(stderr, "Could not execute because dotnet-%s does not exist.\n" "Go to https://developer.samsung.com/tizen to learn how to install tools.\n\n", argv[0]); @@ -138,26 +138,26 @@ int main(int argc, const char* argv[]) { argv++; } - std::string currentExeAbsolutePath = absolutePath("/proc/self/exe"); + std::string currentExeAbsolutePath = getAbsolutePath("/proc/self/exe"); if (currentExeAbsolutePath.empty()) { fprintf(stderr, "Failed to get the current executable's absolute path.\n"); return -1; } - std::string clrFilesAbsolutePath = absolutePath(clrFilesPath); + std::string clrFilesAbsolutePath = getAbsolutePath(clrFilesPath); if (clrFilesAbsolutePath.empty()) { fprintf(stderr, "Failed to resolve the full path to the CLR files.\n"); return -1; } - std::string managedAssemblyAbsolutePath = absolutePath(managedAssemblyPath); + std::string managedAssemblyAbsolutePath = getAbsolutePath(managedAssemblyPath); if (managedAssemblyAbsolutePath.empty()) { fprintf(stderr, "Failed to get the managed assembly's absolute path.\n"); return -1; } std::string coreclrLibPath(clrFilesAbsolutePath + "/libcoreclr.so"); - std::string appPath = baseName(managedAssemblyAbsolutePath); + std::string appPath = getBaseName(managedAssemblyAbsolutePath); std::string nativeDllSearchDirs(appPath); nativeDllSearchDirs += ":" + additionalProbingPath; nativeDllSearchDirs += ":" + clrFilesAbsolutePath; diff --git a/NativeLauncher/launcher/lib/dotnet_launcher.cc b/NativeLauncher/launcher/lib/dotnet_launcher.cc index 599ab24..2e1bfe6 100644 --- a/NativeLauncher/launcher/lib/dotnet_launcher.cc +++ b/NativeLauncher/launcher/lib/dotnet_launcher.cc @@ -562,7 +562,7 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i return -1; } - if (!isFileExist(path)) { + if (!isFile(path)) { _ERR("File not exist : %s", path); return -1; } diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc index fa0608a..ff4db07 100644 --- a/NativeLauncher/tool/dotnettool.cc +++ b/NativeLauncher/tool/dotnettool.cc @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) return -1; } - NiCommonOption option = {std::string(), std::string(), std::string()}; + NICommonOption option = {std::string(), std::string(), std::string()}; if (initNICommon(&option) != NI_ERROR_NONE) { return -1; } @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) it = args.erase(it); std::string ibcFilePath = std::string(*it); - if (!isDirectoryExist(ibcFilePath)) { + if (!isDirectory(ibcFilePath)) { fprintf(stderr, "IBC path is missing or not exist\n"); return -1; } @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) //sh-3.2# dotnettool --ni-system if (cmd == "--ni-system") { - int ret = createNiPlatform(flags); + int ret = createNIPlatform(flags); if (ret != NI_ERROR_NONE) { fprintf(stderr, "Failed to generate system NI\n"); } @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) } while (it != args.end()) { std::string dll = std::string(*it); - int ret = createNiDll(dll, flags); + int ret = createNIDll(dll, flags); if (ret != NI_ERROR_NONE) { fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str()); break; @@ -161,7 +161,7 @@ int main(int argc, char* argv[]) while (it != args.end()) { std::string pkg = std::string(*it); // if there is AOTed dlls under package root, that is skiped. - int ret = createNiUnderPkgRoot(pkg, flags); + int ret = createNIUnderPkgRoot(pkg, flags); if (ret != NI_ERROR_NONE) { fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str()); break; @@ -183,7 +183,7 @@ int main(int argc, char* argv[]) it = args.erase(it); while (it != args.end()) { std::string dll = std::string(*it); - int ret = createNiDllUnderPkgRoot(pkg, dll, flags); + int ret = createNIDllUnderPkgRoot(pkg, dll, flags); if (ret != NI_ERROR_NONE) { fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str()); break; @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) } while (it != args.end()) { const std::string dir[] = {std::string(*it)}; - int ret = createNiUnderDirs(dir, 1, flags); + int ret = createNIUnderDirs(dir, 1, flags); if (ret != NI_ERROR_NONE) { fprintf(stderr, "Failed to generate NI directory\n"); break; @@ -209,7 +209,7 @@ int main(int argc, char* argv[]) } //sh-3.2# dotnettool --ni-reset-system else if (cmd == "--ni-reset-system") { - removeNiPlatform(); + removeNIPlatform(); } //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ... else if (cmd == "--ni-reset-pkg") { @@ -218,7 +218,7 @@ int main(int argc, char* argv[]) } while (it != args.end()) { std::string pkg = std::string(*it); - int ret = removeNiUnderPkgRoot(pkg); + int ret = removeNIUnderPkgRoot(pkg); if (ret != NI_ERROR_NONE) { fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str()); break; @@ -238,7 +238,7 @@ int main(int argc, char* argv[]) } while (it != args.end()) { const std::string dir[] = {std::string(*it)}; - removeNiUnderDirs(dir, 1); + removeNIUnderDirs(dir, 1); it = args.erase(it); } } diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 527a7fd..970bbb2 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -76,7 +76,7 @@ static void waitInterval() } } -static std::string getNiFilePath(const std::string& dllPath) +static std::string getNIFilePath(const std::string& dllPath) { size_t index = dllPath.find_last_of("."); if (index == std::string::npos) { @@ -110,7 +110,7 @@ static std::string getAppNIPath(const std::string& niPath) niDirPath = concatPath(prevPath, APP_NI_SUB_DIR); - if (!isFileExist(niDirPath)) { + if (!isFile(niDirPath)) { if (mkdir(niDirPath.c_str(), 0755) == 0) { copySmackAndOwnership(prevPath, niDirPath); } else { @@ -121,14 +121,14 @@ static std::string getAppNIPath(const std::string& niPath) return concatPath(niDirPath, fileName); } -static bool niExist(const std::string& path) +static bool checkNIExistence(const std::string& path) { - std::string f = getNiFilePath(path); + std::string f = getNIFilePath(path); if (f.empty()) { return false; } - if (isFileExist(f)) { + if (isFile(f)) { return true; } @@ -136,7 +136,7 @@ static bool niExist(const std::string& path) // original file to support new coreclr if (path.find("System.Private.CoreLib.dll") != std::string::npos) { std::string coreLibBackup = path + ".Backup"; - if (isFileExist(coreLibBackup)) { + if (isFile(coreLibBackup)) { return true; } } @@ -171,7 +171,7 @@ static uintptr_t getNextBaseAddr() { uintptr_t baseAddr = 0; - if (!isFileExist(__SYSTEM_BASE_FILE)) { + if (!isFile(__SYSTEM_BASE_FILE)) { // This is the starting address for all default base addresses baseAddr = DEFAULT_BASE_ADDR_START; } else { @@ -186,11 +186,11 @@ static uintptr_t getNextBaseAddr() } // Save base address of system ni image to file -static void updateBaseAddrFile(const std::string &absNiPath, uintptr_t baseAddr) +static void updateBaseAddrFile(const std::string &absNIPath, uintptr_t baseAddr) { - uintptr_t niSize = getFileSize(absNiPath); + uintptr_t niSize = getFileSize(absNIPath); if (niSize == 0) { - fprintf(stderr, "File %s doesn't exist\n", absNiPath.c_str()); + fprintf(stderr, "File %s doesn't exist\n", absNIPath.c_str()); return; } @@ -208,7 +208,7 @@ static void updateBaseAddrFile(const std::string &absNiPath, uintptr_t baseAddr) // check if dll is listed in TPA static bool isTPADll(const std::string &dllPath) { - std::string absDllPath = absolutePath(dllPath); + std::string absDllPath = getAbsolutePath(dllPath); if (__tpa.find(absDllPath) != std::string::npos) { return true; @@ -221,7 +221,7 @@ static bool isTPADll(const std::string &dllPath) // baseAddr should be checked in file before getting here static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, DWORD flags) { - if (!isFileExist(dllPath)) { + if (!isFile(dllPath)) { fprintf(stderr, "dll file is not exist : %s\n", dllPath.c_str()); return NI_ERROR_NO_SUCH_FILE; } @@ -231,23 +231,23 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat return NI_ERROR_INVALID_PARAMETER; } - if (niExist(dllPath)) { + if (checkNIExistence(dllPath)) { fprintf(stderr, "Already ni file is exist for %s\n", dllPath.c_str()); return NI_ERROR_ALREADY_EXIST; } - std::string absDllPath = absolutePath(dllPath); - std::string absNiPath = getNiFilePath(dllPath); + std::string absDllPath = getAbsolutePath(dllPath); + std::string absNIPath = getNIFilePath(dllPath); - if (absNiPath.empty()) { + if (absNIPath.empty()) { fprintf(stderr, "Fail to get ni file name\n"); return NI_ERROR_UNKNOWN; } bool isAppNI = flags & NI_FLAGS_APPNI; - if (isAppNI && strstr(absNiPath.c_str(), __DOTNET_DIR) == NULL) { - absNiPath = getAppNIPath(absNiPath); + if (isAppNI && strstr(absNIPath.c_str(), __DOTNET_DIR) == NULL) { + absNIPath = getAppNIPath(absNIPath); } #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT @@ -266,13 +266,13 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat int status; waitpid(pid, &status, 0); if (WIFEXITED(status)) { - // Do not use niExist() function to check whether ni file created or not. - // niEixst() return false for System.Private.Corelib.dll - if (isFileExist(absNiPath)) { - copySmackAndOwnership(absDllPath, absNiPath); + // Do not use checkNIExistence() function to check whether ni file created or not. + // checkNIExistence() return false for System.Private.Corelib.dll + if (isFile(absNIPath)) { + copySmackAndOwnership(absDllPath, absNIPath); std::string absPdbPath = replaceAll(absDllPath, ".dll", ".pdb"); - std::string pdbFilePath = replaceAll(absNiPath, ".ni.dll", ".pdb"); - if (isFileExist(absPdbPath) && (absPdbPath != pdbFilePath)) { + std::string pdbFilePath = replaceAll(absNIPath, ".ni.dll", ".pdb"); + if (isFile(absPdbPath) && (absPdbPath != pdbFilePath)) { if (!copyFile(absPdbPath, pdbFilePath)) { fprintf(stderr, "Failed to copy a .pdb file\n"); } else { @@ -281,7 +281,7 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat } #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT if (baseAddr != 0) { - updateBaseAddrFile(absNiPath, baseAddr); + updateBaseAddrFile(absNIPath, baseAddr); } #endif return NI_ERROR_NONE; @@ -327,12 +327,12 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat if (!appPath.empty()) { absAppPath = appPath; } else { - absAppPath = baseName(absDllPath); + absAppPath = getBaseName(absDllPath); } argv.push_back(absAppPath.c_str()); argv.push_back("/out"); - argv.push_back(absNiPath.c_str()); + argv.push_back(absNIPath.c_str()); argv.push_back(absDllPath.c_str()); argv.push_back(nullptr); @@ -359,7 +359,7 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData) return -1; } - if (removeNiUnderPkgRoot(pkgId) != NI_ERROR_NONE) { + if (removeNIUnderPkgRoot(pkgId) != NI_ERROR_NONE) { fprintf(stderr, "Failed to remove previous dlls from [%s]\n", pkgId); return -1; } @@ -370,7 +370,7 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData) } // Regenerate ni files with R2R mode forcibiliy. (there is no way to now which option is used) - if (createNiUnderPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) { + if (createNIUnderPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) { fprintf(stderr, "Failed to generate NI file [%s]\n", pkgId); return -1; } else { @@ -394,7 +394,7 @@ static bool isCoreLibPrepared(DWORD flags) } std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup"); - if (isFileExist(coreLibBackup)) { + if (isFile(coreLibBackup)) { return true; } else { fprintf(stderr, "The native image of System.Private.CoreLib does not exist\n" @@ -410,7 +410,7 @@ static ni_error_e createCoreLibNI(DWORD flags) std::string niCoreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.ni.dll"); std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup"); - if (!isFileExist(coreLibBackup)) { + if (!isFile(coreLibBackup)) { if (!crossgen(coreLib, std::string(), flags)) { if (rename(coreLib.c_str(), coreLibBackup.c_str())) { fprintf(stderr, "Failed to rename System.Private.CoreLib.dll\n"); @@ -428,7 +428,7 @@ static ni_error_e createCoreLibNI(DWORD flags) return NI_ERROR_NONE; } -ni_error_e initNICommon(NiCommonOption* option) +ni_error_e initNICommon(NICommonOption* option) { #if defined(__arm__) // get interval value @@ -468,17 +468,17 @@ void finalizeNICommon() } -ni_error_e createNiPlatform(DWORD flags) +ni_error_e createNIPlatform(DWORD flags) { if (createCoreLibNI(flags) != NI_ERROR_NONE) { return NI_ERROR_CORE_NI_FILE; } const std::string platformDirs[] = {getRuntimeDir(), getTizenFXDir()}; - return createNiUnderDirs(platformDirs, 2, flags); + return createNIUnderDirs(platformDirs, 2, flags); } -ni_error_e createNiDll(const std::string& dllPath, DWORD flags) +ni_error_e createNIDll(const std::string& dllPath, DWORD flags) { if (dllPath.find("System.Private.CoreLib.dll") != std::string::npos) { return createCoreLibNI(flags); @@ -491,7 +491,7 @@ ni_error_e createNiDll(const std::string& dllPath, DWORD flags) return crossgen(dllPath, std::string(), flags); } -void createNiUnderTAC(std::vector nugets, DWORD flags) +void createNIUnderTAC(std::vector nugets, DWORD flags) { std::string appPaths; for (auto& nuget : nugets) { @@ -538,8 +538,8 @@ ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags) 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)) { + std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + if (!bf::exists(originNIPath)) { flags |= NI_FLAGS_APPNI; if(crossgen(originPath, paths, flags) != NI_ERROR_NONE) { fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str()); @@ -548,7 +548,7 @@ ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags) } std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll"; if (!bf::exists(symNIPath)) { - bf::create_symlink(originNiPath, symNIPath); + bf::create_symlink(originNIPath, symNIPath); fprintf(stdout, "%s symbolic link file generated successfully.\n", symNIPath.c_str()); copySmackAndOwnership(tacDir.c_str(), symNIPath.c_str(), true); @@ -568,7 +568,7 @@ ni_error_e createTACPkgRoot(const std::string& pkgId, DWORD flags) return NI_ERROR_NONE; } -ni_error_e createNiUnderDirs(const std::string rootPaths[], int count, DWORD flags) +ni_error_e createNIUnderDirs(const std::string rootPaths[], int count, DWORD flags) { if (!isCoreLibPrepared(flags)) { return NI_ERROR_CORE_NI_FILE; @@ -609,7 +609,7 @@ ni_error_e createNiUnderDirs(const std::string rootPaths[], int count, DWORD fla return NI_ERROR_NONE; } -ni_error_e createNiUnderPkgRoot(const std::string& pkgId, DWORD flags) +ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags) { std::string pkgRoot; if (getRootPath(pkgId, pkgRoot) < 0) { @@ -623,10 +623,10 @@ ni_error_e createNiUnderPkgRoot(const std::string& pkgId, DWORD flags) std::string paths[] = {binDir, libDir, tacDir}; flags |= NI_FLAGS_APPNI; - return createNiUnderDirs(paths, 3, flags); + return createNIUnderDirs(paths, 3, flags); } -ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string& dllPath, DWORD flags) +ni_error_e createNIDllUnderPkgRoot(const std::string& pkgId, const std::string& dllPath, DWORD flags) { if (!isCoreLibPrepared(flags)) { return NI_ERROR_CORE_NI_FILE; @@ -648,21 +648,21 @@ ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string& if (bf::exists(tacDir)) { if (!isNativeImage(dllPath)) { std::string originPath = bf::read_symlink(dllPath).string(); - std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; - if (!bf::exists(originNiPath)) { + std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + if (!bf::exists(originNIPath)) { flags |= NI_FLAGS_APPNI; if(crossgen(originPath, paths, flags) != NI_ERROR_NONE) { fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str()); return NI_ERROR_UNKNOWN; } } - std::string setNiPath = dllPath.substr(0, dllPath.rfind(".dll")) + ".ni.dll"; - if (!bf::exists(setNiPath)) { - bf::create_symlink(originNiPath, setNiPath); - fprintf(stdout, "%s symbolic link file generated successfully.\n", setNiPath.c_str()); - copySmackAndOwnership(tacDir.c_str(), setNiPath.c_str(), true); + std::string setNIPath = dllPath.substr(0, dllPath.rfind(".dll")) + ".ni.dll"; + if (!bf::exists(setNIPath)) { + bf::create_symlink(originNIPath, setNIPath); + fprintf(stdout, "%s symbolic link file generated successfully.\n", setNIPath.c_str()); + copySmackAndOwnership(tacDir.c_str(), setNIPath.c_str(), true); } - std::string niFileName = setNiPath.substr(setNiPath.rfind('/') + 1); + std::string niFileName = setNIPath.substr(setNIPath.rfind('/') + 1); if (!removeFile(concatPath(binNIDir, niFileName))) { fprintf(stderr, "Failed to remove of %s\n", concatPath(binNIDir, niFileName).c_str()); } @@ -685,17 +685,17 @@ ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string& } } -void removeNiPlatform() +void removeNIPlatform() { std::string coreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll"); std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup"); - if (!isFileExist(coreLibBackup)) { + if (!isFile(coreLibBackup)) { return; } #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT - if (isFileExist(__SYSTEM_BASE_FILE)) { + if (isFile(__SYSTEM_BASE_FILE)) { if (remove(__SYSTEM_BASE_FILE)) { fprintf(stderr, "Failed to remove %s\n", __SYSTEM_BASE_FILE); } @@ -712,10 +712,10 @@ void removeNiPlatform() const std::string platformDirs[] = {getRuntimeDir(), getTizenFXDir()}; - removeNiUnderDirs(platformDirs, 2); + removeNIUnderDirs(platformDirs, 2); } -void removeNiUnderDirs(const std::string rootPaths[], int count) +void removeNIUnderDirs(const std::string rootPaths[], int count) { auto convert = [](const std::string& path, const std::string& filename) { if (isNativeImage(path)) { @@ -730,7 +730,7 @@ void removeNiUnderDirs(const std::string rootPaths[], int count) } } -ni_error_e removeNiUnderPkgRoot(const std::string& pkgId) +ni_error_e removeNIUnderPkgRoot(const std::string& pkgId) { std::string pkgRoot; if (getRootPath(pkgId, pkgRoot) < 0) { @@ -742,17 +742,17 @@ ni_error_e removeNiUnderPkgRoot(const std::string& pkgId) std::string libDir = concatPath(pkgRoot, "lib"); std::string paths[] = {binDir, libDir}; - removeNiUnderDirs(paths, 2); + removeNIUnderDirs(paths, 2); std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR); - if (isFileExist(binNIDir)) { + if (isFile(binNIDir)) { if (!removeAll(binNIDir.c_str())) { fprintf(stderr, "Failed to remove app ni dir [%s]\n", binNIDir.c_str()); } } std::string libNIDir = concatPath(libDir, APP_NI_SUB_DIR); - if (isFileExist(libNIDir)) { + if (isFile(libNIDir)) { if (!removeAll(libNIDir.c_str())) { fprintf(stderr, "Failed to remove app ni dir [%s]\n", libNIDir.c_str()); } @@ -820,7 +820,7 @@ static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData) tac_db = NULL; } - createNiUnderTAC(nugets, *pFlags); + createNIUnderTAC(nugets, *pFlags); return 0; } @@ -832,7 +832,7 @@ ni_error_e regenerateTACNI(DWORD flags) } const std::string tacDir[] = {__DOTNET_DIR}; - removeNiUnderDirs(tacDir, 1); + removeNIUnderDirs(tacDir, 1); pkgmgrinfo_appinfo_metadata_filter_h handle; int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle); diff --git a/NativeLauncher/tool/nitool.cc b/NativeLauncher/tool/nitool.cc index 0b55ac4..841be72 100644 --- a/NativeLauncher/tool/nitool.cc +++ b/NativeLauncher/tool/nitool.cc @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) bool rmPkgMode = false; bool pkgDllMode = false; - NiCommonOption option = {std::string(), std::string(), std::string()}; + NICommonOption option = {std::string(), std::string(), std::string()}; if (initNICommon(&option) != NI_ERROR_NONE) { return -1; } @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) help(argv[0]); return 0; } else if (cmdOptionExists(argv, argv+argc, "--system")) { - createNiPlatform(flags); + createNIPlatform(flags); return 0; } else if (cmdOptionExists(argv, argv+argc, "--dll")) { dllMode = true; @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) } else if (cmdOptionExists(argv, argv+argc, "--dir")) { dirMode = true; } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) { - removeNiPlatform(); + removeNIPlatform(); return 0; } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) { rmPkgMode = true; @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) if (pkgMode) { for (const std::string pkg : args) { // if there is AOTed dlls under package root, that is skiped. - int ret = createNiUnderPkgRoot(pkg, flags); + int ret = createNIUnderPkgRoot(pkg, flags); if (ret == NI_ERROR_INVALID_PACKAGE) { fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str()); return -1; @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) } } } else if (pkgDllMode) { - int ret = createNiDllUnderPkgRoot(args[0], args[1], flags); + int ret = createNIDllUnderPkgRoot(args[0], args[1], flags); if (ret == NI_ERROR_INVALID_PACKAGE) { fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str()); return -1; @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) } } else if (rmPkgMode) { for (const std::string pkg : args) { - int ret = removeNiUnderPkgRoot(pkg); + int ret = removeNIUnderPkgRoot(pkg); if (ret == NI_ERROR_INVALID_PACKAGE) { fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str()); return -1; @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) // donot return error code for generation failure. // we have to run crossgen for all input dlls. for (const std::string dll : args) { - int ret = createNiDll(dll, flags); + int ret = createNIDll(dll, flags); if (ret == NI_ERROR_ALREADY_EXIST) { // skip for already exist case } else if (ret != NI_ERROR_NONE) { @@ -156,7 +156,7 @@ int main(int argc, char* argv[]) } } } else if (dirMode) { - createNiUnderDirs(args.data(), args.size(), flags); + createNIUnderDirs(args.data(), args.size(), flags); } return 0; diff --git a/NativeLauncher/util/path_manager.cc b/NativeLauncher/util/path_manager.cc index a00e247..e4761c2 100644 --- a/NativeLauncher/util/path_manager.cc +++ b/NativeLauncher/util/path_manager.cc @@ -59,13 +59,13 @@ int initializePathManager(const std::string& runtimeDir, const std::string& tize } if (!runtimeDir.empty()) { - __dllPath->runtime_dir = absolutePath(runtimeDir); + __dllPath->runtime_dir = getAbsolutePath(runtimeDir); } else { - __dllPath->runtime_dir = absolutePath(__RUNTIME_DIR); + __dllPath->runtime_dir = getAbsolutePath(__RUNTIME_DIR); } if (!tizenFXDir.empty()) { - __dllPath->tizenfx_dir = absolutePath(tizenFXDir); + __dllPath->tizenfx_dir = getAbsolutePath(tizenFXDir); } else { char* tmp = vconf_get_str(__TIZEN_API_PATH_KEY); if (tmp) { @@ -73,7 +73,7 @@ int initializePathManager(const std::string& runtimeDir, const std::string& tize _DBG("Device API Directory is set by vconf : %s", tmp); free(tmp); } else { - __dllPath->tizenfx_dir = absolutePath(__DEVICE_API_DIR); + __dllPath->tizenfx_dir = getAbsolutePath(__DEVICE_API_DIR); } } @@ -129,7 +129,7 @@ static std::string getPlatformTPA() { std::string platform_tpa; - if (isFileExist(PLATFORM_TPA_CACHE)) { + if (isFile(PLATFORM_TPA_CACHE)) { _INFO("platform tpa cache found."); std::ifstream cacheFile; cacheFile.open(PLATFORM_TPA_CACHE); diff --git a/NativeLauncher/util/plugin_manager.cc b/NativeLauncher/util/plugin_manager.cc index 88cd6d4..c9e25d2 100644 --- a/NativeLauncher/util/plugin_manager.cc +++ b/NativeLauncher/util/plugin_manager.cc @@ -30,7 +30,7 @@ int initializePluginManager(const char* mode) return 0; } - if (isFileExist(PLUGIN_PATH)) { + if (isFile(PLUGIN_PATH)) { __pluginLib = dlopen(PLUGIN_PATH, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE); if (__pluginLib) { __pluginFunc = (PluginFunc*)calloc(sizeof(PluginFunc), 1); diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index cab3ab2..22df38b 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -100,7 +100,7 @@ void splitPath(const std::string& path, std::vector& out) } } -std::string absolutePath(const std::string& path) +std::string getAbsolutePath(const std::string& path) { std::string absPath; char *realPath = realpath(path.c_str(), NULL); @@ -217,7 +217,7 @@ int getMetadataValue(std::string pkgId, std::string metadataKey, std::string& me return 0; } -std::string baseName(const std::string& path) +std::string getBaseName(const std::string& path) { auto pos = path.find_last_of(PATH_SEPARATOR); if (pos != std::string::npos) @@ -241,13 +241,13 @@ std::string replaceAll(const std::string &str, const std::string &pattern, const return result; } -bool isFileExist(const std::string& path) +bool isFile(const std::string& path) { struct stat sb; return stat(path.c_str(), &sb) == 0; } -bool isDirectoryExist(const std::string& path) +bool isDirectory(const std::string& path) { struct stat sb; if (stat(path.c_str(), &sb) != 0) { @@ -299,7 +299,7 @@ void addAssembliesFromDirectories(const std::vector& directories, s // 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. - if (baseName(assemPaths[assem]).compare(baseName(path)) == 0) + if (getBaseName(assemPaths[assem]).compare(getBaseName(path)) == 0) assemPaths[assem] = path; } }