Add optionis to remove app NI file
authorWoongsuk Cho <ws77.cho@samsung.com>
Fri, 29 Mar 2024 02:03:33 +0000 (11:03 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Thu, 9 May 2024 00:31:35 +0000 (09:31 +0900)
In case of OS upgrade, there are cases where all app-related ni files must be removed.
For that case, add new options to dotnettool

- ni-reset-all-app
- tac-reset-all

NativeLauncher/inc/ni_common.h
NativeLauncher/tool/dotnettool.cc
NativeLauncher/tool/ni_common.cc

index 28b387fa72829348b289b2b76731e136a1a57479..94ae7e4bb9b6440b3375aef8fd0b3ca92949257b 100644 (file)
@@ -137,16 +137,18 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId);
 /**
  * @brief regenerate native images of all installed packages (tpk, rpk)
  * @param[in] flags additional flags for the image generator
+ * @param[in] removeOnly if it is set true, ni creation is skipped (default : false)
  * @return ni_error_e
  */
-ni_error_e regeneratePkgNI(NIOption* opt);
+ni_error_e regeneratePkgNI(NIOption* opt, bool removeOnly = false);
 
 /**
  * @brief regenerate native image of TAC for all shared assembly.
  * @param[in] flags additional flags for the image generator
+ * @param[in] removeOnly if it is set true, ni creation is skipped. (default : false)
  * @return ni_error_e
  */
-ni_error_e regenerateTACNI(NIOption* opt);
+ni_error_e regenerateTACNI(NIOption* opt, bool removeOnly = false);
 
 /**
  * @brief Sets the priority of the process to the specified values from -20 to 19.(default : 0)
index 39b5206ee0e48cbdd2de28087400738c4a2bcd00..fbd2db78e7a8d4bea7fecb7aba036a27389a7fac 100644 (file)
@@ -41,9 +41,11 @@ void DisplayUsage() {
                "                                   (If package is installed under RO area, NI files are generated under RW area)\n"
                "       --ni-dir                  - Create NI for directory\n"
                "       --ni-reset-system         - Remove System NI files\n"
+               "       --ni-reset-all-app        - Remove All App NI files\n"
                "       --ni-reset-pkg            - Remove App NI files\n"
                "       --ni-reset-dir            - Remove NI for directory\n"
                "       --ni-regen-all-app        - Re-generate All App NI files\n"
+               "       --tac-reset-all           - Remove All TAC NI files\n"
                "       --tac-regen-all           - Re-generate All TAC files\n"
                "       --tac-restore-db          - Restore TAC Database\n"
                "       --tac-disable-pkg         - Disable TAC for package\n"
@@ -305,6 +307,13 @@ int main(int argc, char* argv[])
        else if (cmd == "--ni-reset-system") {
                removeNIPlatform();
        }
+       //sh-3.2# dotnettool --ni-reset-all-app
+       else if (cmd == "--ni-reset-all-app") {
+               int ret = regeneratePkgNI(opt, true);
+               if (ret != NI_ERROR_NONE) {
+                       _SERR("Failed to reset all app NI");
+               }
+       }
        //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
        else if (cmd == "--ni-reset-pkg") {
                if (args.size() < 1) {
@@ -344,6 +353,13 @@ int main(int argc, char* argv[])
                        _SERR("Failed to regenerate all app NI");
                }
        }
+       //sh-3.2# dotnettool --tac-reset-all
+       else if (cmd == "--tac-reset-all") {
+               int ret = regenerateTACNI(opt, true);
+               if (ret != NI_ERROR_NONE) {
+                       _SERR("Failed to remove all TAC NI files");
+               }
+       }
        //sh-3.2# dotnettool --tac-regen-all
        else if (cmd == "--tac-regen-all") {
                if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
index 3b463cf95fd6dc36936dfb090c0d7cb91214534b..38db04f1e4142febf5ab6ffb9d1f1fdaa6002c5b 100644 (file)
@@ -813,22 +813,6 @@ static ni_error_e doAOTFile(const std::string& dllFile, const std::string& refPa
        return doAOTList(dllList, refPaths, opt);
 }
 
-static ni_error_e removeAndCreateNI(const char* pkgId, NIOption* pOptions)
-{
-       if (removeNIUnderPkgRoot(pkgId) != NI_ERROR_NONE) {
-               _SERR("Failed to remove previous dlls from [%s]", pkgId);
-               return NI_ERROR_UNKNOWN;
-       }
-
-       if (createNIUnderPkgRoot(pkgId, pOptions) != NI_ERROR_NONE) {
-               _SERR("Failed to generate NI file [%s]", pkgId);
-               return NI_ERROR_UNKNOWN;
-       }
-
-       _SOUT("Complete make native image for pkg (%s)", pkgId);
-       return NI_ERROR_NONE;
-}
-
 static bool isReadOnlyPkg(std::string pkgId)
 {
        int ret = 0;
@@ -1224,7 +1208,7 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId)
        return NI_ERROR_NONE;
 }
 
-ni_error_e regeneratePkgNI(NIOption* opt)
+ni_error_e regeneratePkgNI(NIOption* opt, bool removeOnly)
 {
        std::vector<std::string> pkgList;
        ni_error_e ret = NI_ERROR_NONE;
@@ -1275,11 +1259,18 @@ ni_error_e regeneratePkgNI(NIOption* opt)
                        continue;
                }
 
-               if (removeAndCreateNI(pkg.c_str(), opt) != NI_ERROR_NONE) {
+               if (removeNIUnderPkgRoot(pkg) != NI_ERROR_NONE) {
                        _SERR("Failed to remove previous dlls from [%s]", pkg.c_str());
                        ret = NI_ERROR_UNKNOWN;
-               } else {
-                       _SOUT("Complete make application to native image");
+               }
+
+               if (!removeOnly) {
+                       if (createNIUnderPkgRoot(pkg, opt) != NI_ERROR_NONE) {
+                               _SERR("Failed to generate NI file [%s]", pkg.c_str());
+                               ret = NI_ERROR_UNKNOWN;
+                       } else {
+                               _SOUT("Complete make application to native image");
+                       }
                }
        }
 
@@ -1342,30 +1333,32 @@ static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData)
        return 0;
 }
 
-ni_error_e regenerateTACNI(NIOption* opt)
+ni_error_e regenerateTACNI(NIOption* opt, bool removeOnly)
 {
        removeNIUnderDirs(__DOTNET_DIR);
 
-       pkgmgrinfo_appinfo_metadata_filter_h handle;
-       int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
-       if (ret != PMINFO_R_OK) {
-               return NI_ERROR_UNKNOWN;
-       }
+       if (!removeOnly) {
+               pkgmgrinfo_appinfo_metadata_filter_h handle;
+               int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
+               if (ret != PMINFO_R_OK) {
+                       return NI_ERROR_UNKNOWN;
+               }
 
-       ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-               return NI_ERROR_UNKNOWN;
-       }
+               ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE);
+               if (ret != PMINFO_R_OK) {
+                       pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+                       return NI_ERROR_UNKNOWN;
+               }
+
+               ret = pkgmgrAppMDFilterForeach(handle, regenTacCb, &opt);
+               if (ret != 0) {
+                       pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+                       return NI_ERROR_UNKNOWN;
+               }
 
-       ret = pkgmgrAppMDFilterForeach(handle, regenTacCb, &opt);
-       if (ret != 0) {
                pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-               return NI_ERROR_UNKNOWN;
        }
 
-       pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-
        return NI_ERROR_NONE;
 }