From: j-h.choi Date: Mon, 18 Nov 2024 06:53:12 +0000 (+0900) Subject: Remove temporary files and folders when NI generation fails X-Git-Tag: accepted/tizen/unified/20250115.124144~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6717fd24cbd3b9a11cac566fa3c5eb1e6a9ba52a;p=platform%2Fcore%2Fdotnet%2Flauncher.git Remove temporary files and folders when NI generation fails Change-Id: I42d4b393684efef79d28198860303e6997de9304 --- diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 0bc29ba..3754715 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -703,6 +703,19 @@ static void renameAppNITmpPath(NIOption* opt) } } +static void removeAppNITmpPath(NIOption* opt) +{ + std::string niTmpPath = __pm->getAppRootPath() + "/bin/" + APP_NI_SUB_TMP_DIR; + + if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) { + niTmpPath = replaceAll(niTmpPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR); + } + + if (isDirectory(niTmpPath)) { + removeAll(niTmpPath); + } +} + static ni_error_e doAOTList(std::vector& dllList, const std::string& refPaths, NIOption* opt) { ni_error_e ret = NI_ERROR_NONE; @@ -782,24 +795,42 @@ static ni_error_e doAOTList(std::vector& dllList, const std::string } } - if (ret == NI_ERROR_NONE) { - if (opt->flags & NI_FLAGS_INPUT_BUBBLE) { - for (auto &dll : dllList) { - std::string tmpFile; - std::string niFile = getNIFilePath(dll, opt); - tmpFile = niFile + ".tmp"; - - if (exist(tmpFile)) { - moveFile(tmpFile, niFile); - _SOUT("Native image %s generated successfully.", niFile.c_str()); - } + if (ret != NI_ERROR_NONE) { + for (auto &dll : dllList) { + std::string niFile1 = getNIFilePath(dll, opt); + std::string niFile2 = replaceAll(niFile1, "/.native_image_tmp/", "/"); + if (opt->flags & NI_FLAGS_INPUT_BUBBLE) { + removeFile(niFile1 + ".tmp"); + removeFile(niFile2 + ".tmp"); + } else { + removeFile(niFile1); + removeFile(niFile2); } } + if (opt->flags & NI_FLAGS_APPNI) { - renameAppNITmpPath(opt); + removeAppNITmpPath(opt); + } + return ret; + } + + if (opt->flags & NI_FLAGS_INPUT_BUBBLE) { + for (auto &dll : dllList) { + std::string tmpFile; + std::string niFile = getNIFilePath(dll, opt); + tmpFile = niFile + ".tmp"; + + if (exist(tmpFile)) { + moveFile(tmpFile, niFile); + _SOUT("Native image %s generated successfully.", niFile.c_str()); + } } } + if (opt->flags & NI_FLAGS_APPNI) { + renameAppNITmpPath(opt); + } + return ret; } @@ -1232,6 +1263,10 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId) _SERR("Failed to remove app ni dir [%s]", path.c_str()); } } + std::string niTmpPath = replaceAll(path, "/.native_image", "/.native_image_tmp"); + if (isDirectory(niTmpPath)) { + removeAll(niTmpPath); + } } } }