[Refactoring] Code cleanup and remove duplicate methods
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / tac_installer.cc
index 6e7d377..6bf9b57 100644 (file)
@@ -40,16 +40,16 @@ static const char* __DOTNET_DIR = __STR(DOTNET_DIR);
 #undef __STR
 #undef __XSTR
 
-std::vector<std::string> nugetPackagesAssembliesSha;
-std::vector<std::string> tacDB;
-std::vector<std::string> createDirectories;
-std::vector<std::string> createLibraries;
-std::vector<std::string> updateTac;
-tac_state tacState = TAC_STATE_NONE;
+static std::vector<std::string> nugetPackagesAssembliesSha;
+static std::vector<std::string> tacDB;
+static std::vector<std::string> createDirectories;
+static std::vector<std::string> createLibraries;
+static std::vector<std::string> updateTac;
+static tac_state tacState = TAC_STATE_NONE;
 static sqlite3 *tac_db = NULL;
 static sqlite3 *tlc_db = NULL;
-bool tacPluginInstalled = false;
-bool tacPluginFinished = false;
+static bool tacPluginInstalled = false;
+static bool tacPluginFinished = false;
 
 static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
 {
@@ -121,7 +121,7 @@ static bool copyAssemblyCreateSymlink(std::string binPath, std::string tacDir, s
                                                nuget_restoration = true;
                                                break;
                                        }
-                                       if (!copyFile(concatPath(binNiPath, niFile), concatPath(tac_version_dir, niFile))) {
+                                       if (exist(binNiPath) && !copyFile(concatPath(binNiPath, niFile), concatPath(tac_version_dir, niFile))) {
                                                _ERR("Failed to copy of %s", niFile.c_str());
                                        }
                                }
@@ -131,7 +131,7 @@ static bool copyAssemblyCreateSymlink(std::string binPath, std::string tacDir, s
                                        nuget_restoration = true;
                                        break;
                                }
-                               if (exist(concatPath(tac_version_dir, niFile))) {
+                               if (exist(concatPath(tac_version_dir, niFile)) && exist(binNiPath)) {
                                        bf::create_symlink(concatPath(tac_version_dir, niFile), concatPath(tacDir, niFile), error);
                                        if (error) {
                                                _ERR("Failed to create symlink %s file", concatPath(tacDir, niFile).c_str());
@@ -260,6 +260,11 @@ int tacInstall(const std::string& pkgId, tac_state state, bool tacForce)
        }
 
        std::string binPath = concatPath(rootPath, "bin");
+       if (exist(concatPath(binPath, PRE_COMPILED_PACKAGE_FILE))) {
+               _INFO("The %s is a Pre-Compiled package. So, skip the TAC", pkgId.c_str());
+               return 0;
+       }
+
        std::string metaValue = getMetadataValue(pkgId, TAC_METADATA_KEY);
        if (!tacForce) {
                if (metaValue.empty()) {
@@ -492,6 +497,11 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
        }
 
        std::string binPath = concatPath(rootPath, "bin");
+       if (exist(concatPath(binPath, PRE_COMPILED_PACKAGE_FILE))) {
+               _INFO("The %s is a Pre-Compiled package. So, skip the TAC", pkgId.c_str());
+               state = TAC_STATE_REMOVED;
+       }
+
        if (state == TAC_STATE_REMOVED) {
                _INFO("Skipped to parse of deps.json");
        } else { //TAC_STATE_UPGRADE
@@ -987,7 +997,7 @@ void install_Clean()
        }
 
        for (auto& cl : createLibraries) {
-               changeOwnershipTAC(cl);
+               copySmackAndOwnership(__DOTNET_DIR, cl);
        }
 }