Add flags to the install plugin to avoid duplicate execution
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_nuget_cache_plugin.cc
index b042405..0d87f66 100644 (file)
@@ -39,7 +39,7 @@
 
 #define __XSTR(x) #x
 #define __STR(x) __XSTR(x)
-static const char* __TAC_DIR = __STR(TAC_DIR);
+static const char* __DOTNET_DIR = __STR(DOTNET_DIR);
 #undef __STR
 #undef __XSTR
 
@@ -57,6 +57,8 @@ std::string rootPath;
 std::string execName;
 std::string binPath;
 static sqlite3 *tac_db = NULL;
+bool tacPluginInstalled = false;
+bool tacPluginFinished = false;
 
 bool metadataCheck(GList *list)
 {
@@ -261,6 +263,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_INSTALL =====]");
        _INFO("PackageID : %s", pkgId);
 
+       // Can be multiple apps in one package
+       if (tacPluginInstalled) {
+               _INFO("TAC plugin already installed");
+               return 0;
+       }
+       tacPluginInstalled = true;
+
        if (!appTypeCheck(std::string(pkgId))) {
                _INFO("App type is not dotnet");
                return 0;
@@ -295,7 +304,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                _INFO("TAC name : %s", tac_name.c_str());
                _INFO("TAC version : %s", tac_version.c_str());
 
-               std::string tac_version_dir = concatPath(__TAC_DIR, np);
+               std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
                std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
                if (!bf::exists(tac_version_dir)) {
                        _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
@@ -370,7 +379,7 @@ int updateTacDB(sqlite3 *sqlite)
                        return -1;
                }
                if (count == 0) {
-                       std::string tac_version_dir_prev = concatPath(__TAC_DIR, unp);
+                       std::string tac_version_dir_prev = concatPath(__DOTNET_DIR, unp);
                        std::string tac_version_dir_backup = tac_version_dir_prev + ".bck";
                        if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
                                _ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
@@ -393,6 +402,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
        _INFO("PackageID : %s", pkgId);
 
+       // Can be multiple apps in one package
+       if (tacPluginInstalled) {
+               _INFO("TAC plugin already upgraded");
+               return 0;
+       }
+       tacPluginInstalled = true;
+
        if (!appTypeCheck(std::string(pkgId))) {
                _INFO("App type is not dotnet");
                return 0;
@@ -438,7 +454,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app
                        _INFO("TAC name : %s", tac_name.c_str());
                        _INFO("TAC version : %s", tac_version.c_str());
 
-                       std::string tac_version_dir = concatPath(__TAC_DIR, np);
+                       std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
                        std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
                        if (!bf::exists(tac_version_dir)) {
                                _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
@@ -554,6 +570,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *a
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNINSTALL =====]");
        _INFO("PackageID : %s", pkgId);
 
+       // Can be multiple apps in one package
+       if (tacPluginInstalled) {
+               _INFO("TAC plugin already uninstalled");
+               return 0;
+       }
+       tacPluginInstalled = true;
+
        status = "uninstall";
        tac_db = dbOpen(TAC_APP_LIST_DB);
        if (!tac_db) {
@@ -587,7 +610,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *app
 
 void cleanStep(std::string tac)
 {
-       std::string current_tac = concatPath(__TAC_DIR, tac.substr(0, tac.find('/')));
+       std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
        try {
                for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
                        std::string bck_path = bck.path().string();
@@ -645,6 +668,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_CLEAN =====]");
        _INFO("PackageID : %s", pkgId);
 
+       // Can be multiple apps in one package
+       if (tacPluginFinished) {
+               _INFO("TAC plugin already finished(CLEAN)");
+               return 0;
+       }
+       tacPluginFinished = true;
+
        if (tac_db) {
                dbClose(tac_db);
                tac_db = NULL;
@@ -661,7 +691,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId
 
 void undoStep(std::string tac)
 {
-       std::string current_tac = concatPath(__TAC_DIR, tac.substr(0, tac.find('/')));
+       std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
        try {
                for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
                        std::string bck_path = bck.path().string();
@@ -710,6 +740,13 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId,
        _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNDO =====]");
        _INFO("PackageID : %s", pkgId);
 
+       // Can be multiple apps in one package
+       if (tacPluginFinished) {
+               _INFO("TAC plugin already finished(UNDO)");
+               return 0;
+       }
+       tacPluginFinished = true;
+
        if (tac_db) {
                dbRollback(tac_db);
                tac_db = NULL;