Changed API to check internet privilege
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / ni_common.cc
index cecda2a..54e1c0b 100644 (file)
@@ -189,7 +189,7 @@ static bool isTPADll(const std::string& dllPath)
 
 /**
  * @brief create the directory including parents directory, and
- *        copy ownership and smack labels to the created directory.
+ *          copy ownership and smack labels to the created directory.
  * @param[in] target directory path
  * @param[in] source directory path to get ownership and smack label
  * @return if directory created successfully, return true otherwise false
@@ -492,6 +492,12 @@ static ni_error_e crossgen2PostAction(const std::string& dllPath, const std::str
                }
        }
 
+       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+               if (!removeFile(dllPath)) {
+                       _SERR("Fail to remove original file : %s", dllPath.c_str());
+               }
+       }
+
        if (!(opt->flags & NI_FLAGS_INPUT_BUBBLE && opt->flags & NI_FLAGS_NO_PIPELINE)) {
                _SOUT("Native image %s generated successfully.", outFile.c_str());
        }
@@ -647,7 +653,15 @@ static ni_error_e createCoreLibNI(NIOption* opt)
 
        if (!isFile(coreLibBackup) && !isR2RImage(coreLib)) {
                if (crossgen2NoPipeLine(dllList, refPaths, opt) == NI_ERROR_NONE) {
-                       if (rename(coreLib.c_str(), coreLibBackup.c_str())) {
+                       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+                               std::ofstream output(coreLibBackup);
+                               if (!exist(coreLibBackup)) {
+                                       _SERR("Failed to create System.Private.CoreLib.dll.Backup");
+                                       return NI_ERROR_CORE_NI_FILE;
+                               }
+                               copySmackAndOwnership(__pm->getRuntimePath(), coreLibBackup, false);
+                               output.close();
+                       } else if (rename(coreLib.c_str(), coreLibBackup.c_str())) {
                                _SERR("Failed to rename from System.Private.CoreLib.dll to System.Private.CoreLib.dll.Backup");
                                return NI_ERROR_CORE_NI_FILE;
                        }
@@ -683,24 +697,21 @@ static ni_error_e doAOTList(std::vector<std::string>& dllList, const std::string
        std::string coreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll");
        bool hasSPC = false;
 
-       std::vector<std::string> niList;
        for (auto it = dllList.begin(); it != dllList.end(); it++) {
                std::string f = *it;
                if (!isFile(f)) {
                        _SERR("dll file is not exist : %s", f.c_str());
                        dllList.erase(it--);
                }
-               if (!isManagedAssembly(f)) {
+               else if (!isManagedAssembly(f)) {
                        _SERR("Input file is not a dll file : %s", f.c_str());
                        dllList.erase(it--);
                }
                // handle System.Private.CoreLib.dll separately.
                // dllList and path manager contain absolute path. So, there is no need to change path to absolute path
-               if (f == coreLib) {
+               else if (f == coreLib) {
                        hasSPC = true;
                        dllList.erase(it--);
-               } else {
-                       niList.push_back(changeExtension(f, ".dll", ".ni.dll"));
                }
        }
 
@@ -1091,8 +1102,13 @@ void removeNIUnderDirs(const std::string& rootPaths)
 {
        auto convert = [](const std::string& path, const std::string& filename) {
                if (isNativeImage(path)) {
-                       if (remove(path.c_str())) {
-                               _SERR("Failed to remove %s", path.c_str());
+                       std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll");
+                       if (exist(assemblyPath)) {
+                               if (remove(path.c_str())) {
+                                       _SERR("Failed to remove %s", path.c_str());
+                               }
+                       } else {
+                               _SOUT("%s cannot be removed because there is no %s", path.c_str(), assemblyPath.c_str());
                        }
                }
        };