Skip app ni regeneration if app ni already exist (#344) submit/tizen/20210723.041054
author조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Fri, 23 Jul 2021 04:08:27 +0000 (13:08 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 23 Jul 2021 04:08:27 +0000 (13:08 +0900)
To avoid multiple NI file generation for --ni-pkg, skip app ni regeneration if app ni already exist

NativeLauncher/tool/ni_common.cc

index 51a04b3..80af20e 100644 (file)
@@ -150,8 +150,8 @@ static std::string getAppNIFilePath(const std::string& absDllPath, DWORD flags)
 
        if (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. So, create NI files in RW area(%s).", niDirPath.c_str());
-               _ERR("App is installed in RO area. So, create NI files in RW area(%s).", niDirPath.c_str());
+               _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)) {
@@ -164,21 +164,20 @@ static std::string getAppNIFilePath(const std::string& absDllPath, DWORD flags)
        return getNIFilePath(concatPath(niDirPath, getFileName(absDllPath)));
 }
 
-static bool checkNIExistence(const std::string& path)
+static bool checkNIExistence(const std::string& absDllPath, const std::string& absNIPath)
 {
-       std::string f = getNIFilePath(path);
-       if (f.empty()) {
+       if (absNIPath.empty()) {
                return false;
        }
 
-       if (isFile(f)) {
+       if (isFile(absNIPath)) {
                return true;
        }
 
        // native image of System.Private.CoreLib.dll should have to overwrite
        // original file to support new coreclr
-       if (path.find("System.Private.CoreLib.dll") != std::string::npos) {
-               std::string coreLibBackup = path + ".Backup";
+       if (absDllPath.find("System.Private.CoreLib.dll") != std::string::npos) {
+               std::string coreLibBackup = absDllPath + ".Backup";
                if (isFile(coreLibBackup)) {
                        return true;
                }
@@ -288,11 +287,6 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
                return NI_ERROR_INVALID_PARAMETER;
        }
 
-       if (checkNIExistence(dllPath)) {
-               //_SERR("Already ni file is exist for %s", dllPath.c_str());
-               return NI_ERROR_ALREADY_EXIST;
-       }
-
        std::string absDllPath = getAbsolutePath(dllPath);
        std::string absNIPath;
 
@@ -308,6 +302,11 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
                return NI_ERROR_UNKNOWN;
        }
 
+       if (checkNIExistence(absDllPath, absNIPath)) {
+               //_SERR("Already ni file is exist for %s", absNIPath.c_str());
+               return NI_ERROR_ALREADY_EXIST;
+       }
+
 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
        uintptr_t baseAddr = 0;
 
@@ -429,6 +428,11 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
                return -1;
        }
 
+       if (removeNIUnderPkgRoot(pkgId) != NI_ERROR_NONE) {
+               _SERR("Failed to remove previous dlls from [%s]", pkgId);
+               return -1;
+       }
+
        if (createNIUnderPkgRoot(pkgId, *pFlags) != NI_ERROR_NONE) {
                _SERR("Failed to generate NI file [%s]", pkgId);
                return -1;
@@ -651,11 +655,6 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, DWORD flags)
                flags |= NI_FLAGS_APP_UNDER_RO_AREA;
        } else {
                flags &= ~NI_FLAGS_APP_UNDER_RO_AREA;
-               ni_error_e err = removeNIUnderPkgRoot(pkgId);
-               if (err != NI_ERROR_NONE) {
-                       _SERR("Failed to remove previous dlls from [%s]", pkgId.c_str());
-                       return err;
-               }
        }
 
        // create native image under bin and lib directory
@@ -724,13 +723,15 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId)
        std::vector<std::string> paths;
        splitPath(appNIPaths, paths);
        for (const auto &path : paths) {
-               // Only the native image inside the TAC should be removed.
-               if (strstr(path.c_str(), TAC_SYMLINK_SUB_DIR) != NULL) {
-                       removeNIUnderDirs(path);
-               } else {
-                       if (isDirectory(path)) {
-                               if (!removeAll(path.c_str())) {
-                                       _SERR("Failed to remove app ni dir [%s]", path.c_str());
+               if (!isReadOnlyArea(path)) {
+                       // Only the native image inside the TAC should be removed.
+                       if (strstr(path.c_str(), TAC_SYMLINK_SUB_DIR) != NULL) {
+                               removeNIUnderDirs(path);
+                       } else {
+                               if (isDirectory(path)) {
+                                       if (!removeAll(path.c_str())) {
+                                               _SERR("Failed to remove app ni dir [%s]", path.c_str());
+                                       }
                                }
                        }
                }