From 9f8c470f8f7d30fc13ae3420277feca1cccd7a1f Mon Sep 17 00:00:00 2001 From: "j-h.choi" Date: Tue, 6 Oct 2020 14:31:35 +0900 Subject: [PATCH] Modify the ownership of TAC and Remove unnecessary logs Change-Id: Ie50d7d54069d4ae160ab444a8bae5260ccb9449f --- .../installer-plugin/prefer_nuget_cache_plugin.cc | 30 +++++++++++++++++++--- NativeLauncher/tool/tac_common.cc | 18 ------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc b/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc index f241865..30518b1 100644 --- a/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc +++ b/NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc @@ -150,7 +150,6 @@ static bool copyAssemblyCreateSymlink(std::string binPath, std::string tacDir, s static void copyLibraryCreateSymlink(const char* pkgId, std::vector LibrariesInfo, std::string tlcDir) { if (LibrariesInfo.empty()) { - _INFO("Not exist data for TLC in %s", pkgId); return; } @@ -239,7 +238,6 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app status = "install"; if (tacDB.empty()) { - _INFO("Not exist data for TAC in %s", pkgId); return 0; } @@ -348,6 +346,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app _ERR("Cannot create directory: %s", tlcDir.c_str()); return 0; } + copySmackAndOwnership(__DOTNET_DIR, tlcDir); tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE); if (!tlc_db) { @@ -503,7 +502,6 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app tac_updateDB(tac_db); skipTLC = true; - _INFO("Not exist data for TAC in %s", pkgId); } else { std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR); if (!createDir(tac_dir)) { @@ -664,6 +662,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *app _ERR("Cannot create directory: %s", tlcDir.c_str()); return 0; } + copySmackAndOwnership(__DOTNET_DIR, tlcDir); tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE); if (!tlc_db) { @@ -889,6 +888,17 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, return 0; } +void changeOwnershipTAC(std::string current_tac) +{ + copySmackAndOwnership(__DOTNET_DIR, current_tac); + try { + for (auto& path : bf::recursive_directory_iterator(current_tac)) + copySmackAndOwnership(__DOTNET_DIR, path.path().string()); + } catch (const bf::filesystem_error& error) { + _ERR("Failed to recursive directory: %s", error.what()); + } +} + void cleanStep(std::string tac) { std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/'))); @@ -935,7 +945,13 @@ void cleanStep(std::string tac) void install_Clean() { - return; + for (auto& cd : createDirectories) { + changeOwnershipTAC(cd); + } + + for (auto& cl : createLibraries) { + changeOwnershipTAC(cl); + } } void unInstall_Clean() @@ -947,9 +963,11 @@ void unInstall_Clean() void update_Clean() { + install_Clean(); if (!tacDB.empty()) { for (auto& np : tacDB) { cleanStep(np); + changeOwnershipTAC(concatPath(__DOTNET_DIR, np.substr(0, np.find('/')))); } } unInstall_Clean(); @@ -1013,11 +1031,15 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId if (tac_db) { closeDB(tac_db); tac_db = NULL; + copySmackAndOwnership(__DOTNET_DIR, TAC_APP_LIST_DB); + copySmackAndOwnership(__DOTNET_DIR, TAC_APP_LIST_DB + std::string("-journal")); } if (tlc_db) { closeDB(tlc_db); tlc_db = NULL; + copySmackAndOwnership(__DOTNET_DIR, TLC_APP_LIST_DB); + copySmackAndOwnership(__DOTNET_DIR, TLC_APP_LIST_DB + std::string("-journal")); } return 0; diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 54da934..eed13a2 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -180,9 +180,6 @@ tac_error_e tac_restoreDB() tac_db = NULL; } - const uid_t g_uid = 301; // app_fw - const gid_t g_gid = 301; // app_fw - if (!copyFile(TAC_APP_LIST_RESTORE_DB, TAC_APP_LIST_DB)) { fprintf(stderr, "Failed to copy of %s\n", TAC_APP_LIST_DB); return TAC_ERROR_UNKNOWN; @@ -191,9 +188,6 @@ tac_error_e tac_restoreDB() fprintf(stderr, "Failed to remove of %s\n", TAC_APP_LIST_RESTORE_DB); return TAC_ERROR_UNKNOWN; } - if (chown(TAC_APP_LIST_DB, g_uid, g_gid) == -1) { - fprintf(stderr, "Failed to change owner and group name\n"); - } std::string dbJournal = TAC_APP_LIST_DB + std::string("-journal"); if (!copyFile(dbRestoreJournal, dbJournal)) { @@ -204,9 +198,6 @@ tac_error_e tac_restoreDB() fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str()); return TAC_ERROR_UNKNOWN; } - if (chown(dbJournal.c_str(), g_uid, g_gid) == -1) { - fprintf(stderr, "Failed to change owner and group name\n"); - } cleanupDirectory(); @@ -521,9 +512,6 @@ tac_error_e tlc_restoreDB() tlc_db = NULL; } - const uid_t g_uid = 301; // app_fw - const gid_t g_gid = 301; // app_fw - if (!copyFile(TLC_APP_LIST_RESTORE_DB, TLC_APP_LIST_DB)) { fprintf(stderr, "Failed to copy of %s\n", TLC_APP_LIST_DB); return TAC_ERROR_UNKNOWN; @@ -532,9 +520,6 @@ tac_error_e tlc_restoreDB() fprintf(stderr, "Failed to remove of %s\n", TLC_APP_LIST_RESTORE_DB); return TAC_ERROR_UNKNOWN; } - if (chown(TLC_APP_LIST_DB, g_uid, g_gid) == -1) { - fprintf(stderr, "Failed to change owner and group name\n"); - } std::string dbJournal = TLC_APP_LIST_DB + std::string("-journal"); if (!copyFile(dbRestoreJournal, dbJournal)) { @@ -545,9 +530,6 @@ tac_error_e tlc_restoreDB() fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str()); return TAC_ERROR_UNKNOWN; } - if (chown(dbJournal.c_str(), g_uid, g_gid) == -1) { - fprintf(stderr, "Failed to change owner and group name\n"); - } auto convert = [](const std::string& path, const std::string& filename) { bool isExist = false; -- 2.7.4