add command to nitool to remove system and app ni 10/174510/1 submit/tizen/20180402.112712
authorCho Woong Suk <ws77.cho@samsung.com>
Mon, 2 Apr 2018 11:25:56 +0000 (20:25 +0900)
committerCho Woong Suk <ws77.cho@samsung.com>
Mon, 2 Apr 2018 11:25:56 +0000 (20:25 +0900)
Change-Id: I0b223900bfcdc708706c79920721acaa761a0aa6

NativeLauncher/installer-plugin/common.cc
NativeLauncher/installer-plugin/common.h
NativeLauncher/installer-plugin/nitool.cc

index f1d212e..7d826db 100644 (file)
@@ -255,6 +255,40 @@ static void createCoreLibNI()
        }
 }
 
+void removeNiUnderDirs(const char* rootPaths[], int count)
+{
+       auto convert = [](const char* path, const char* name) {
+               std::string ni;
+               if (isNativeImage(path)) {
+                       remove(path);
+               }
+       };
+
+       for (int i = 0; i < count; i++)
+               scanFilesInDir(rootPaths[i], convert, -1);
+}
+
+void removeNiPlatform()
+{
+       std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll");
+       std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll");
+       std::string coreLibBackup = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll.Backup");
+
+       if (fileNotExist(coreLibBackup)) {
+               return;
+       }
+
+       if (remove(coreLib.c_str())) {
+               _ERR("Failed to remove System.Private.CoreLib native image file");
+       }
+
+       rename(coreLibBackup.c_str(), coreLib.c_str());
+
+       const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"};
+
+       removeNiUnderDirs(platformDirs, 3);
+}
+
 void createNiPlatform()
 {
        createCoreLibNI();
@@ -334,6 +368,28 @@ void createNiUnderDirs(const char* rootPaths[], int count)
        createNiUnderDirs(rootPaths, count, nullptr);
 }
 
+int removeNiUnderPkgRoot(const char* pkgName)
+{
+       std::string pkgRoot;
+       if (getRootPath(pkgName, pkgRoot) < 0)
+               return 1;
+
+       std::string binDir = concatPath(pkgRoot, "bin");
+       std::string libDir = concatPath(pkgRoot, "lib");
+       _INFO("bindir : %s", binDir.c_str());
+       _INFO("libdir : %s", libDir.c_str());
+
+       const char* paths[] = {
+               binDir.c_str(),
+               libDir.c_str()
+       };
+
+       removeNiUnderDirs(paths, 2);
+
+       return 0;
+}
+
+
 int createNiUnderPkgRoot(const char* pkgName)
 {
        std::string pkgRoot;
index d36ae69..941f5b1 100644 (file)
@@ -26,5 +26,7 @@ void createNiUnderDirs(const char* rootPaths[], int count);
 int createNiUnderPkgRoot(const char* pkgName);
 void createNiPlatform();
 void createNiSelect(const char* dllPath);
+void removeNiPlatform();
+int removeNiUnderPkgRoot(const char* pkgName);
 
 #endif /* __INSTALLER_PLUGIN_COMMON_H__ */
index c34a696..081d638 100644 (file)
@@ -45,6 +45,8 @@ static void help(const char *argv0)
                "               --system                - Create NI under System DLLs\n"
                "               --dll                   - Create NI for DLL\n"
                "               --pkg                   - Create NI for package\n"
+               "               --reset-system  - Remove System NI files\n"
+               "               --reset-pkg             - Remove App NI files\n"
                "\n"
                "Example:\n"
                "Create native image for dlls and exes under platform directories\n"
@@ -60,6 +62,7 @@ int main(int argc, char* argv[])
 {
        bool pkgMode = false;
        bool dllMode = false;
+       bool rmPkgMode = false;
 
        if (cmdOptionExists(argv, argv+argc, "--help")) {
                help(argv[0]);
@@ -71,6 +74,11 @@ int main(int argc, char* argv[])
                dllMode = true;
        } else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
                pkgMode = true;
+       } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
+               removeNiPlatform();
+               return 0;
+       } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
+               rmPkgMode = true;
        } else {
                help(argv[0]);
                return 1;
@@ -94,6 +102,13 @@ int main(int argc, char* argv[])
                                return 1;
                        }
                }
+       } else if (rmPkgMode) {
+               for (const char* pkg : args) {
+                       if (removeNiUnderPkgRoot(pkg) != 0) {
+                               fprintf(stderr, "Failed to get root path from [%s]\n", pkg);
+                               return 1;
+                       }
+               }
        } else if (dllMode) {
                for (const char* dll : args)
                        createNiSelect(dll);