Separate the code related to the profile data into a profile_common file
authorj-h.choi <j-h.choi@samsung.com>
Tue, 14 Jun 2022 06:54:12 +0000 (15:54 +0900)
committer조웅석/Common Platform Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Tue, 5 Jul 2022 00:36:07 +0000 (09:36 +0900)
Change-Id: I6c62e7a26f502651333458473202b6d438f46261

NativeLauncher/CMakeLists.txt
NativeLauncher/inc/ni_common.h
NativeLauncher/inc/profile_common.h [new file with mode: 0644]
NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc
NativeLauncher/tool/dotnettool.cc
NativeLauncher/tool/ni_common.cc
NativeLauncher/tool/profile_common.cc [new file with mode: 0644]
packaging/dotnet-launcher.spec

index 89c3c1a081f2397a59bc076c5c211a34ae7d1715..67461939099dec1501fae51fab95dbbe6c8bc212 100644 (file)
@@ -198,6 +198,14 @@ SET_TARGET_PROPERTIES(${NI_COMMON} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB})
 TARGET_INCLUDE_DIRECTORIES(${NI_COMMON} PRIVATE ${RUNTIME_DIR}/src/ ${RUNTIME_DIR}/src/pal ${RUNTIME_DIR}/src/pal/inc ${RUNTIME_DIR}/src/pal/inc/rt)
 TARGET_LINK_LIBRARIES(${NI_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${TAC_COMMON})
 
+SET(PROFILE_COMMON "profile_common")
+SET(${PROFILE_COMMON}_SOURCE_FILES
+    tool/profile_common.cc
+)
+ADD_LIBRARY(${PROFILE_COMMON} SHARED ${${PROFILE_COMMON}_SOURCE_FILES})
+SET_TARGET_PROPERTIES(${PROFILE_COMMON} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB})
+TARGET_LINK_LIBRARIES(${PROFILE_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL})
+
 SET(MULTI_TARGET_RESOLVER "multi_target_resolver")
 SET(${MULTI_TARGET_RESOLVER}_SOURCE_FILES
     tool/multi_target_resolver.cc
@@ -220,7 +228,7 @@ SET(${DOTNETTOOL}_SOURCE_FILES
 )
 ADD_EXECUTABLE(${DOTNETTOOL} ${${DOTNETTOOL}_SOURCE_FILES})
 SET_TARGET_PROPERTIES(${DOTNETTOOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_EXE})
-TARGET_LINK_LIBRARIES(${DOTNETTOOL} ${${PROJECT_NAME}_LDFLAGS} "-pie" ${DOTNET_LAUNCHER_UTIL} ${NI_COMMON} ${TAC_COMMON} ${MULTI_TARGET_RESOLVER})
+TARGET_LINK_LIBRARIES(${DOTNETTOOL} ${${PROJECT_NAME}_LDFLAGS} "-pie" ${DOTNET_LAUNCHER_UTIL} ${NI_COMMON} ${TAC_COMMON} ${PROFILE_COMMON} ${MULTI_TARGET_RESOLVER})
 
 SET(PREFER_DOTNET_AOT_PLUGIN "prefer_dotnet_aot_plugin")
 SET(${PREFER_DOTNET_AOT_PLUGIN}_SOURCE_FILES
@@ -267,6 +275,7 @@ INSTALL(TARGETS ${DOTNET_CORERUN} DESTINATION ${BINDIR})
 INSTALL(TARGETS ${DOTNET_HYDRA_LOADER} DESTINATION ${BINDIR})
 INSTALL(TARGETS ${TAC_COMMON} DESTINATION ${LIBDIR})
 INSTALL(TARGETS ${NI_COMMON} DESTINATION ${LIBDIR})
+INSTALL(TARGETS ${PROFILE_COMMON} DESTINATION ${LIBDIR})
 INSTALL(TARGETS ${MULTI_TARGET_RESOLVER} DESTINATION ${LIBDIR})
 INSTALL(TARGETS ${TPATOOL} DESTINATION ${BINDIR})
 INSTALL(TARGETS ${DOTNETTOOL} DESTINATION ${BINDIR})
@@ -283,6 +292,7 @@ INSTALL(FILES inc/coreclr_host.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES inc/dotnet_launcher_plugin.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES inc/ni_common.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES inc/tac_common.h DESTINATION ${INCLUDEDIR})
+INSTALL(FILES inc/profile_common.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES ../dotnet-launcher.pc DESTINATION ${LIBDIR}/pkgconfig)
 INSTALL(FILES dotnet-launcher.info DESTINATION /usr/share/parser-plugins)
 IF(DEFINED BUILD_DOTNET_PLUGIN)
index 22f69e4ac7f800c98f2642ef4563ec3adc8560f2..725ae7ccebc765337438edc3f282591a15c4f5cf 100644 (file)
@@ -144,16 +144,4 @@ ni_error_e regenerateAppNI(NIOption* opt);
  */
 ni_error_e regenerateTACNI(NIOption* opt);
 
-/**
- * @brief remove app profile data of a package
- * @param[in] pkgId package ID
- * @return ni_error_e
- */
-ni_error_e removeAppProfileData(const std::string& pkgId);
-
-/**
- * @brief remove all app profile data
- */
-void removeAllAppProfileData();
-
 #endif /* __NI_COMMON_H__ */
diff --git a/NativeLauncher/inc/profile_common.h b/NativeLauncher/inc/profile_common.h
new file mode 100644 (file)
index 0000000..7495a23
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PROFILE_COMMON_H__
+#define __PROFILE_COMMON_H__
+
+#include <functional>
+#include <string>
+
+typedef enum {
+       PROFILE_ERROR_NONE = 0,
+       PROFILE_ERROR_INVALID_PARAMETER = -1,
+       PROFILE_ERROR_UNKNOWN = -9
+} profile_error_e;
+
+/**
+ * @brief remove app profile data of a package
+ * @param[in] pkgId package id
+ * @return profile_error_e
+ */
+profile_error_e removeAppProfileData(const std::string& pkgId);
+
+/**
+ * @brief remove all app profile data
+ */
+void removeAllAppProfileData();
+
+#endif /* __PROFILE_COMMON_H__ */
index d7f32a4b902606111961a47ac239d3a82579710f..c5c9786d0ebc71993ca79924a7104bc01068acc5 100644 (file)
@@ -18,6 +18,7 @@
 #include "utils.h"
 #include "multi_target_resolver.h"
 #include "ni_common.h"
+#include "profile_common.h"
 #include "launcher_env.h"
 
 #include <vector>
@@ -77,7 +78,7 @@ extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId)
                return 0;
        }
 
-       if (removeAppProfileData(pkgId) != NI_ERROR_NONE) {
+       if (removeAppProfileData(pkgId) != PROFILE_ERROR_NONE) {
                _ERR("Failed to remove [%s] profile data", pkgId);
        }
 
index 8c10ce4e096859f7c5bdd2a2c14d241cced51257..749ad36c971746cab25c021df524b6ec6e2edce0 100644 (file)
@@ -17,6 +17,7 @@
 #include "utils.h"
 #include "ni_common.h"
 #include "tac_common.h"
+#include "profile_common.h"
 #include "multi_target_resolver.h"
 #include "log.h"
 
@@ -361,7 +362,7 @@ int main(int argc, char* argv[])
                }
                while (it != args.end()) {
                        std::string pkg = std::string(*it);
-                       if (removeAppProfileData(pkg) != NI_ERROR_NONE) {
+                       if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) {
                                _SERR("Failed to remove [%s] profile data", pkg.c_str());
                        }
                        it = args.erase(it);
index ea63ecfa8285a9c738953683fb6514eb2ba72e10..0b3134fbe1f75988cbebc8855ffd925b38de98fe 100644 (file)
@@ -17,7 +17,6 @@
 #include <pkgmgr-info.h>
 #include <pkgmgr_installer_info.h>
 #include <aul.h>
-#include <tzplatform_config.h>
 
 #include "log.h"
 #include "utils.h"
@@ -32,7 +31,6 @@
 #include <fstream>
 #include <sstream>
 
-#include <pwd.h>
 #include <grp.h>
 #include <unistd.h>
 #include <string.h>
@@ -1254,124 +1252,3 @@ ni_error_e regenerateTACNI(NIOption* opt)
        return NI_ERROR_NONE;
 }
 
-static std::vector<uid_t> getUserIds()
-{
-       std::vector<uid_t> list;
-
-       while (true) {
-               errno = 0; // so we can distinguish errors from no more entries
-               passwd* entry = getpwent();
-               if (!entry) {
-                       if (errno) {
-                               _SERR("Error while getting userIDs");
-                               list.clear();
-                               return list;
-                       }
-                       break;
-               }
-               list.push_back(entry->pw_uid);
-       }
-       endpwent();
-
-       return list;
-}
-
-static std::string getAppDataPath(const std::string& pkgId, uid_t uid)
-{
-       std::string pDataFile;
-
-       tzplatform_set_user(uid);
-
-       const char* tzUserApp = tzplatform_getenv(TZ_USER_APP);
-       if (tzUserApp != NULL) {
-               pDataFile = std::string(tzUserApp) + "/" + pkgId + "/data/";
-       }
-
-       tzplatform_reset_user();
-
-       return pDataFile;
-}
-
-ni_error_e removeAppProfileData(const std::string& pkgId)
-{
-       if (pkgId.empty()) {
-               return NI_ERROR_INVALID_PARAMETER;
-       }
-
-       std::vector<uid_t> uidList = getUserIds();
-       for (auto& uid : uidList) {
-               // get data path from pkgid
-               std::string dataPath = getAppDataPath(pkgId, uid);
-               if (!dataPath.empty() && exist(dataPath)) {
-                       std::string pDataFile = dataPath + PROFILE_BASENAME;
-
-                       if (exist(pDataFile)) {
-                               if (!removeFile(pDataFile)) {
-                                       _SERR("Fail to remove profile data file (%s).", pDataFile.c_str());
-                                       return NI_ERROR_UNKNOWN;
-                               }
-                               _SOUT("Profile data (%s) is removed successfully", pDataFile.c_str());
-                       }
-               }
-       }
-
-       return NI_ERROR_NONE;
-}
-
-static int appTypeListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
-{
-       char *pkgId = NULL;
-       int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
-       if (ret != PMINFO_R_OK || pkgId == NULL) {
-               _SERR("Fail to get pkgid");
-               return 0;
-       }
-
-       if (removeAppProfileData(pkgId) != NI_ERROR_NONE) {
-               _SERR("Fail to remove profile data for (%s)", pkgId);
-       }
-
-       return 0;
-}
-
-static ni_error_e removeAppProfileByAppType(const char* type)
-{
-       int ret;
-
-       pkgmgrinfo_appinfo_filter_h filter;
-
-       ret = pkgmgrinfo_appinfo_filter_create(&filter);
-       if (ret != PMINFO_R_OK) {
-               _SERR("Fail to create appinfo filter");
-               return NI_ERROR_UNKNOWN;
-       }
-
-       ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_TYPE, type);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_filter_destroy(filter);
-               _SERR("Fail to add appinfo filter (%s)", type);
-               return NI_ERROR_UNKNOWN;
-       }
-
-       ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, appTypeListCb, NULL);
-       if (ret != PMINFO_R_OK) {
-               _SERR("Fail to pkgmgrinfo_pkginfo_filter_foreach_pkginfo");
-               pkgmgrinfo_appinfo_filter_destroy(filter);
-               return NI_ERROR_UNKNOWN;
-       }
-
-       pkgmgrinfo_appinfo_filter_destroy(filter);
-
-       return NI_ERROR_NONE;
-}
-
-void removeAllAppProfileData()
-{
-       std::vector<const char*> appTypeList = {"dotnet", "dotnet-nui", "dotnet-inhouse"};
-
-       for (auto& type : appTypeList) {
-               if (removeAppProfileByAppType(type) != NI_ERROR_NONE) {
-                       _SERR("Fail to removeAppProfileByAppType for type (%s)", type);
-               }
-       }
-}
diff --git a/NativeLauncher/tool/profile_common.cc b/NativeLauncher/tool/profile_common.cc
new file mode 100644 (file)
index 0000000..ace461e
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */\r
+\r
+#include "log.h"
+#include "utils.h"\r
+#include "profile_common.h"\r
+#include "launcher_env.h"\r
+\r
+#include <sys/types.h>\r
+#include <pwd.h>\r
+#include <tzplatform_config.h>\r
+\r
+static std::vector<uid_t> getUserIds()\r
+{
+       std::vector<uid_t> list;
+
+       while (true) {
+               errno = 0; // so we can distinguish errors from no more entries
+               passwd* entry = getpwent();
+               if (!entry) {
+                       if (errno) {
+                               _SERR("Error while getting userIDs");
+                               list.clear();
+                               return list;
+                       }
+                       break;
+               }
+               list.push_back(entry->pw_uid);
+       }
+       endpwent();
+
+       return list;
+}
+
+static std::string getAppDataPath(const std::string& pkgId, uid_t uid)
+{
+       std::string pDataFile;
+
+       tzplatform_set_user(uid);
+
+       const char* tzUserApp = tzplatform_getenv(TZ_USER_APP);
+       if (tzUserApp != NULL) {
+               pDataFile = std::string(tzUserApp) + "/" + pkgId + "/data/";
+       }
+
+       tzplatform_reset_user();
+
+       return pDataFile;
+}\r
+\r
+profile_error_e removeAppProfileData(const std::string& pkgId)\r
+{
+       if (pkgId.empty()) {
+               return PROFILE_ERROR_INVALID_PARAMETER;\r
+       }
+
+       std::vector<uid_t> uidList = getUserIds();
+       for (auto& uid : uidList) {
+               // get data path from pkgid
+               std::string dataPath = getAppDataPath(pkgId, uid);
+               if (!dataPath.empty() && exist(dataPath)) {
+                       std::string pDataFile = dataPath + PROFILE_BASENAME;
+
+                       if (exist(pDataFile)) {
+                               if (!removeFile(pDataFile)) {
+                                       _SERR("Failed to remove profile data file (%s).", pDataFile.c_str());\r
+                                       return PROFILE_ERROR_UNKNOWN;\r
+                               }
+                               _SOUT("Profile data (%s) is removed successfully", pDataFile.c_str());
+                       }
+               }
+       }
+
+       return PROFILE_ERROR_NONE;\r
+}
+
+static int removeAppProfileListCb(pkgmgrinfo_appinfo_h handle, void *user_data)\r
+{
+       char *pkgId = NULL;
+       int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
+       if (ret != PMINFO_R_OK || pkgId == NULL) {
+               _SERR("Failed to get package id");\r
+               return 0;
+       }
+
+       if (removeAppProfileData(pkgId) != PROFILE_ERROR_NONE) {\r
+               _SERR("Failed to remove profile data for (%s)", pkgId);\r
+       }
+
+       return 0;
+}
+
+static void removeAppProfileByAppType(const char* type)\r
+{
+       pkgmgrinfo_appinfo_filter_h filter;\r
+
+       int ret = pkgmgrinfo_appinfo_filter_create(&filter);\r
+       if (ret != PMINFO_R_OK) {
+               _SERR("Failed to create appinfo filter");\r
+               return;\r
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_TYPE, type);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               _SERR("Failed to add appinfo filter (%s)", type);\r
+               return;\r
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, removeAppProfileListCb, NULL);\r
+       if (ret != PMINFO_R_OK) {
+               _SERR("Failed to pkgmgrinfo_pkginfo_filter_foreach_pkginfo");\r
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return;\r
+       }
+
+       pkgmgrinfo_appinfo_filter_destroy(filter);
+
+       return;\r
+}
+
+void removeAllAppProfileData()
+{
+       std::vector<const char*> appTypeList = {"dotnet", "dotnet-nui", "dotnet-inhouse"};
+
+       for (auto& type : appTypeList) {
+               removeAppProfileByAppType(type);\r
+       }
+}\r
+\r
index c51837b279b32dfc72c60ac1a398245f29a7cda5..028289115f07d132c0affe8577f8aa8b8bb781cd 100644 (file)
@@ -217,6 +217,7 @@ chsmack -a User /usr/bin/dotnet-nui-loader
 %{_libdir}/libdotnet_launcher_core.so
 %{_libdir}/libni_common.so
 %{_libdir}/libtac_common.so
+%{_libdir}/libprofile_common.so
 %{_libdir}/libmulti_target_resolver.so
 %{_tmpfilesdir}/%{name}.conf
 /usr/share/parser-plugins/dotnet-launcher.info
@@ -234,11 +235,13 @@ chsmack -a User /usr/bin/dotnet-nui-loader
 %defattr(-,root,root,-)
 %{_includedir}/ni_common.h
 %{_includedir}/tac_common.h
+%{_includedir}/profile_common.h
 %{_includedir}/dotnet_launcher_plugin.h
 %{_includedir}/coreclr_host.h
 %{_libdir}/libdotnet_launcher_util.so
 %{_libdir}/libni_common.so
 %{_libdir}/libtac_common.so
+%{_libdir}/libprofile_common.so
 %{_libdir}/pkgconfig/dotnet-launcher.pc
 %{_framework_dir}/Tizen.Runtime.pdb