bug-fix : fix TAC malfunction for multi pkg scenario
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / tac_installer.cc
index 9644e08..b8b7b66 100644 (file)
@@ -48,8 +48,19 @@ static std::vector<std::string> createLibraries;
 static std::vector<std::string> updateTac;
 static std::vector<std::string> updateTlc;
 static tac_state tacState = TAC_STATE_NONE;
-static bool tacPluginInstalled = false;
-static bool tacPluginFinished = false;
+static std::string prevInstallPkgId = std::string("");
+static std::string prevFinishPkgId = std::string("");
+
+// initialize static vector to support multi-package install scenario
+static void tacInitialize()
+{
+       nugetPackagesAssembliesSha.clear();
+       tacDB.clear();
+       createDirectories.clear();
+       createLibraries.clear();
+       updateTac.clear();
+       updateTlc.clear();
+}
 
 static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
 {
@@ -378,12 +389,14 @@ int tacInstall(const std::string& pkgId, tac_state state, bool tacForce)
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_INSTALL =====]");
        _INFO("PackageID : %s", pkgId.c_str());
 
+       tacInitialize();
+
        // Can be multiple apps in one package
-       if (tacPluginInstalled) {
-               _INFO("TAC plugin already installed");
+       if (strcmp(pkgId.c_str(), prevInstallPkgId.c_str()) == 0) {
+               _INFO("TAC Plugin(INSTALL) already run for same pkgId (%s)", pkgId.c_str());
                return 0;
        }
-       tacPluginInstalled = true;
+       prevInstallPkgId = pkgId;
 
        std::string appType = getAppType(pkgId);
        if (strstr(appType.c_str(), "dotnet") == NULL) {
@@ -422,16 +435,20 @@ int tacInstall(const std::string& pkgId, tac_state state, bool tacForce)
        }
 
        if (generateTAC(pkgId, binPath) != 0) {
+               tac_closeDB();
                return -1;
        }
 
        ///// TLC /////
        if (tlc_createDB() != 0) {
+               tac_closeDB();
                return -1;
        }
 
        copyLibraryCreateSymlink(pkgId, getLibrariesInfo(rootPath));
 
+       tac_closeDB();
+       tlc_closeDB();
        return 0;
 }
 
@@ -440,12 +457,14 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
        _INFO("PackageID : %s", pkgId.c_str());
 
+       tacInitialize();
+
        // Can be multiple apps in one package
-       if (tacPluginInstalled) {
-               _INFO("TAC plugin already upgraded");
+       if (strcmp(pkgId.c_str(), prevInstallPkgId.c_str()) == 0) {
+               _INFO("TAC Plugin(UPGRADE) already run for same pkgId (%s)", pkgId.c_str());
                return 0;
        }
-       tacPluginInstalled = true;
+       prevInstallPkgId = pkgId;
 
        std::string appType = getAppType(pkgId);
        if (strstr(appType.c_str(), "dotnet") == NULL) {
@@ -488,6 +507,7 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
        bool skipTLC = false;
        if (tacDB.empty()) {
                if (tac_deleteDB(pkgId, "") != 0) {
+                       tac_closeDB();
                        return -1;
                }
                tacUpdateDB(pkgId);
@@ -495,6 +515,7 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
                skipTLC = true;
        } else {
                if (generateTAC(pkgId, binPath) != 0) {
+                       tac_closeDB();
                        return -1;
                }
 
@@ -509,6 +530,7 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
                        if (!isExits) {
                                if (tac_deleteDB(pkgId, unp) != 0) {
                                        tacState = TAC_STATE_RESTORE;
+                                       tac_closeDB();
                                        return -1;
                                }
                        }
@@ -518,12 +540,15 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
 
        ///// TLC /////
        if (tlc_createDB() != 0) {
+               tac_closeDB();
                return -1;
        }
 
        updateTlc = tlc_selectDB(pkgId);
 
        if (tlc_deleteDB(pkgId) != 0) {
+               tac_closeDB();
+               tlc_closeDB();
                return -1;
        }
 
@@ -531,6 +556,9 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
 
        copyLibraryCreateSymlink(pkgId, skipTLC ? std::vector<std::string>() : getLibrariesInfo(rootPath));
 
+       tac_closeDB();
+       tlc_closeDB();
+
        return 0;
 }
 
@@ -539,12 +567,14 @@ int tacUninstall(const std::string& pkgId, tac_state state)
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNINSTALL =====]");
        _INFO("PackageID : %s", pkgId.c_str());
 
+       tacInitialize();
+
        // Can be multiple apps in one package
-       if (tacPluginInstalled) {
-               _INFO("TAC plugin already uninstalled");
+       if (strcmp(pkgId.c_str(), prevInstallPkgId.c_str()) == 0) {
+               _INFO("TAC Plugin(UNINSTALL) already run for same pkgId (%s)", pkgId.c_str());
                return 0;
        }
-       tacPluginInstalled = true;
+       prevInstallPkgId = pkgId;
 
        tacState= state;
        if (tac_openDB() != 0) {
@@ -555,23 +585,30 @@ int tacUninstall(const std::string& pkgId, tac_state state)
 
        if (tac_deleteDB(pkgId, "") != 0) {
                tacState = TAC_STATE_RESTORE;
+               tac_closeDB();
                return -1;
        }
        tacUpdateDB(pkgId);
 
        ///// TLC /////
        if (tlc_openDB() != 0) {
+               tac_closeDB();
                return -1;
        }
 
        updateTlc = tlc_selectDB(pkgId);
 
        if (tlc_deleteDB(pkgId) != 0) {
+               tac_closeDB();
+               tlc_closeDB();
                return -1;
        }
 
        tlcUpdateDB(pkgId);
 
+       tac_closeDB();
+       tlc_closeDB();
+
        return 0;
 }
 
@@ -652,11 +689,11 @@ int tacUndo(const std::string& pkgId)
        _INFO("PackageID : %s", pkgId.c_str());
 
        // Can be multiple apps in one package
-       if (tacPluginFinished) {
-               _INFO("TAC plugin already finished(UNDO)");
+       if (strcmp(pkgId.c_str(), prevFinishPkgId.c_str()) == 0) {
+               _INFO("TAC Plugin(UNDO) already run for same pkgId (%s)", pkgId.c_str());
                return 0;
        }
-       tacPluginFinished = true;
+       prevFinishPkgId = pkgId;
 
        if (tacState == TAC_STATE_INSTALL) {
                install_Undo();
@@ -802,11 +839,11 @@ int tacClean(const std::string& pkgId)
        _INFO("PackageID : %s", pkgId.c_str());
 
        // Can be multiple apps in one package
-       if (tacPluginFinished) {
-               _INFO("TAC plugin already finished(CLEAN)");
+       if (strcmp(pkgId.c_str(), prevFinishPkgId.c_str()) == 0) {
+               _INFO("TAC Plugin(CLEAN) already run for same pkgId (%s)", pkgId.c_str());
                return 0;
        }
-       tacPluginFinished = true;
+       prevFinishPkgId = pkgId;
 
        if (tacState == TAC_STATE_INSTALL) {
                install_Clean();