From aef0a17ba441ac6ab2da9af5973077fc14210f15 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Mon, 29 Jul 2019 16:27:38 +0900 Subject: [PATCH 01/16] Fix static analysis issue Use strerror_r instead of strerror for thread safety Change-Id: Icf2e750fb4a18250543355ad613db4bae14cf984 Signed-off-by: Ilho Kim --- src/install_preload_pkg.c | 3 ++- src/pkg_upgrade.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/install_preload_pkg.c b/src/install_preload_pkg.c index 2218344..77e31e1 100644 --- a/src/install_preload_pkg.c +++ b/src/install_preload_pkg.c @@ -62,6 +62,7 @@ static void __make_preload_rw_list(GList *pkg_list) { FILE *file; + char err_buf[BUFSZE]; char pkg_info[BUFSZE]; if (pkg_list == NULL) @@ -70,7 +71,7 @@ static void __make_preload_rw_list(GList *pkg_list) file = fopen(ALL_PRELOAD_RW_PKG_LIST, "a"); if (file == NULL) { _E("can not open [%s]: %s\n", ALL_PRELOAD_RW_PKG_LIST, - strerror(errno)); + strerror_r(errno, err_buf, sizeof(err_buf))); return; } diff --git a/src/pkg_upgrade.c b/src/pkg_upgrade.c index 9078126..4acf3ed 100644 --- a/src/pkg_upgrade.c +++ b/src/pkg_upgrade.c @@ -160,6 +160,7 @@ static void __make_preload_rw_list(GHashTable *preload_rw_table) } FILE *file = NULL; + char buf[BUF_SIZE]; char tmp_path[BUF_SIZE]; snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST); @@ -167,8 +168,8 @@ static void __make_preload_rw_list(GHashTable *preload_rw_table) file = fopen(ALL_PRELOAD_RW_PKG_LIST, "w"); if (file == NULL) { - _LOG("can not open [%s]: %s\n", - ALL_PRELOAD_RW_PKG_LIST, strerror(errno)); + _LOG("can not open [%s]: %s\n", ALL_PRELOAD_RW_PKG_LIST, + strerror_r(errno, buf, sizeof(buf))); return; } g_hash_table_foreach(preload_rw_table, __iter_cb, file); @@ -1265,12 +1266,13 @@ static int __process_rw_fota(GHashTable *preload_rw_table) static int __check_tmp_all_preload_rw_pkg_list() { + char buf[BUF_SIZE]; char tmp_path[BUF_SIZE]; snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST); if (access(tmp_path, F_OK) == 0) { if (rename(tmp_path, ALL_PRELOAD_RW_PKG_LIST)) { _LOG("rename tmp all preload rw pkg list fail : %s\n", - strerror(errno)); + strerror_r(errno, buf, sizeof(buf))); return -1; } } -- 2.7.4 From abc88771ca24f58adacda9ebf5161da9f6920683 Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Tue, 6 Aug 2019 09:53:37 +0900 Subject: [PATCH 02/16] Fix typo Change-Id: I99d45aa84d32b61e83182b545c6499904aa2b8a9 Signed-off-by: Kichan Kwon --- src/pkg_upgrade.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg_upgrade.c b/src/pkg_upgrade.c index 4acf3ed..7612793 100644 --- a/src/pkg_upgrade.c +++ b/src/pkg_upgrade.c @@ -1345,7 +1345,7 @@ int main(int argc, char *argv[]) ret = __process_rw_fota(preload_rw_table); if (ret < 0) { g_hash_table_destroy(preload_rw_table); - _LOGE("__process_ro_fota is failed.\n"); + _LOGE("__process_rw_fota is failed.\n"); return EXIT_FAILURE; } } else { @@ -1360,7 +1360,7 @@ int main(int argc, char *argv[]) ret = __process_rw_fota(preload_rw_table); if (ret < 0) { g_hash_table_destroy(preload_rw_table); - _LOGE("__process_ro_fota is failed.\n"); + _LOGE("__process_rw_fota is failed.\n"); return EXIT_FAILURE; } } else { -- 2.7.4 From cf3754ccabfa0596abf15580ac4b2ec205534015 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Fri, 9 Aug 2019 17:15:44 +0900 Subject: [PATCH 03/16] Release version 0.5.5 Changes: - Fix error when doing FOTA - Fix static analysis issue - Fix typo Change-Id: I75bd87dd660ec853ec397204dda9c735da79820c Signed-off-by: Ilho Kim --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index dc94fbf..4d8fbc1 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.5.4 +Version: 0.5.5 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From c94bd25536d2622810cb52c3686574427d50720e Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Mon, 12 Aug 2019 15:06:29 +0900 Subject: [PATCH 04/16] Fix db migration script Change package_dependency_info's primary key Change-Id: I136c223cedd7f5681668ae32f1b01044fe316097 Signed-off-by: Ilho Kim --- data/updates/upgrade_to_30004.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/updates/upgrade_to_30004.sh.in b/data/updates/upgrade_to_30004.sh.in index d1214e2..67f66b4 100644 --- a/data/updates/upgrade_to_30004.sh.in +++ b/data/updates/upgrade_to_30004.sh.in @@ -14,7 +14,7 @@ function migrate_parser_db() { " depends_on TEXT NOT NULL,\n" \ " type TEXT NOT NULL,\n" \ " required_version TEXT,\n" \ - " PRIMARY KEY(package, depends_on, type, required_version)\n" \ + " PRIMARY KEY(package, depends_on),\n" \ " FOREIGN KEY(package)\n" \ " REFERENCES package_info(package) ON DELETE CASCADE);" | sqlite3 $dbpath -- 2.7.4 From b5f613edafa36b8b4bf2ce6dcfd5efe529ff5edb Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Mon, 12 Aug 2019 15:42:54 +0900 Subject: [PATCH 05/16] Add cert DB upgrade script Change-Id: Ia91e0d9120583401cbc009bd819f2205cf5b8d6d Signed-off-by: Ilho Kim --- data/updates/upgrade_to_30002.sh.in | 5 +++++ data/updates/upgrade_to_30003.sh.in | 5 +++++ data/updates/upgrade_to_30004.sh.in | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/data/updates/upgrade_to_30002.sh.in b/data/updates/upgrade_to_30002.sh.in index 6e19fb6..f77086f 100644 --- a/data/updates/upgrade_to_30002.sh.in +++ b/data/updates/upgrade_to_30002.sh.in @@ -6,6 +6,10 @@ source /etc/tizen-platform.conf PARSER_DB_NAME=.pkgmgr_parser.db PARSER_DB_PATH=$TZ_SYS_DB/$PARSER_DB_NAME +function migrate_cert_db() { + echo "PRAGMA user_version=30002;" | sqlite3 $TZ_SYS_DB/.pkgmgr_cert.db +} + function migrate_parser_db() { local dbpath=$1 @@ -25,3 +29,4 @@ function migrate_user_db() { migrate_parser_db $PARSER_DB_PATH migrate_user_db +migrate_cert_db diff --git a/data/updates/upgrade_to_30003.sh.in b/data/updates/upgrade_to_30003.sh.in index 773ab43..b33bdf6 100644 --- a/data/updates/upgrade_to_30003.sh.in +++ b/data/updates/upgrade_to_30003.sh.in @@ -6,6 +6,10 @@ source /etc/tizen-platform.conf PARSER_DB_NAME=.pkgmgr_parser.db PARSER_DB_PATH=$TZ_SYS_DB/$PARSER_DB_NAME +function migrate_cert_db() { + echo "PRAGMA user_version=30003;" | sqlite3 $TZ_SYS_DB/.pkgmgr_cert.db +} + function migrate_parser_db() { local dbpath=$1 @@ -25,3 +29,4 @@ function migrate_user_db() { migrate_parser_db $PARSER_DB_PATH migrate_user_db +migrate_cert_db diff --git a/data/updates/upgrade_to_30004.sh.in b/data/updates/upgrade_to_30004.sh.in index 67f66b4..faedc8b 100644 --- a/data/updates/upgrade_to_30004.sh.in +++ b/data/updates/upgrade_to_30004.sh.in @@ -6,6 +6,10 @@ source /etc/tizen-platform.conf PARSER_DB_NAME=.pkgmgr_parser.db PARSER_DB_PATH=$TZ_SYS_DB/$PARSER_DB_NAME +function migrate_cert_db() { + echo "PRAGMA user_version=30004;" | sqlite3 $TZ_SYS_DB/.pkgmgr_cert.db +} + function migrate_parser_db() { local dbpath=$1 @@ -38,3 +42,4 @@ function migrate_user_db() { migrate_parser_db $PARSER_DB_PATH migrate_user_db +migrate_cert_db -- 2.7.4 From 58efa1321409ff8ba09e468ed731ab0ed9c1474e Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 20 Aug 2019 10:36:24 +0900 Subject: [PATCH 06/16] Release version 0.5.6 Changes: - Fix db migration script - Add cert DB upgrade script Change-Id: Ibf9f4333e2cb93d80db66ee86f0e2c6a8c236537 Signed-off-by: Ilho Kim --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 4d8fbc1..d4eb399 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.5.5 +Version: 0.5.6 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From 231e0ed90b3fa04e8897b687269c09c6ca19d57f Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 20 Aug 2019 17:16:31 +0900 Subject: [PATCH 07/16] Add new install option This option will be used for fast installation without optimization Related changes [app-installers] https://review.tizen.org/gerrit/#/c/platform/core/appfw/app-installers/+/212328/ [pkgmgr-tool] https://review.tizen.org/gerrit/#/c/platform/core/appfw/pkgmgr-tool/+/212326/ [slp-pkgmgr] https://review.tizen.org/gerrit/#/c/platform/core/appfw/slp-pkgmgr/+/212327/ Change-Id: If850c33ca51769b7e968ec944b01d016e295aa5c Signed-off-by: Ilho Kim --- src/pkg_cmd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index 667d58b..0cca311 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -67,7 +67,7 @@ static int __convert_to_absolute_path(char *path); /* Supported options */ /* Note: 'G' is reserved */ -const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:qhG"; +const char *short_options = "iurwmcgxCkaADL:lsd:p:t:n:T:e:M:X:Y:Z:qhGS"; const struct option long_options[] = { {"install", 0, NULL, 'i'}, {"uninstall", 0, NULL, 'u'}, @@ -102,6 +102,7 @@ const struct option long_options[] = { {"debug-mode", 0, NULL, 'G'}, {"getsizeinfo", 0, NULL, 'x'}, {"uid", 1, NULL, OPTVAL_UID}, + {"skip-optimization", 0, NULL, 'S'}, {0, 0, 0, 0} /* sentinel */ }; @@ -150,6 +151,7 @@ struct pm_tool_args_t { int result; int uid; bool debug_mode; + bool skip_optimization; }; typedef struct pm_tool_args_t pm_tool_args; pm_tool_args data; @@ -439,6 +441,7 @@ static void __print_usage() printf("-G, --debug-mode install the package with debug mode for sdk\n"); printf("-D, --deactivate disable package or app\n"); printf("-A, --activate enable package or app\n"); + printf("-O, --skip-optimization install the package with skip optimization for sdk\n"); printf("-h, --help print this help\n"); printf("\n"); @@ -634,6 +637,9 @@ static int __install_req_dispatcher(uid_t target_uid) if (data.debug_mode) pkgmgr_client_set_debug_mode(pc, true); + if (data.skip_optimization) + pkgmgr_client_set_skip_optimization(pc, true); + if (data.tep_path[0] != '\0') pkgmgr_client_set_tep_path(pc, data.tep_path, data.tep_move); @@ -718,6 +724,9 @@ static int __reinstall_req_dispatcher(uid_t target_uid) if (data.debug_mode) pkgmgr_client_set_debug_mode(pc, true); + if (data.skip_optimization) + pkgmgr_client_set_skip_optimization(pc, true); + ret = pkgmgr_client_usr_reinstall(pc, NULL, data.pkgid, NULL, PM_QUIET, __return_cb, pc, target_uid); if (ret < 0) { @@ -752,6 +761,9 @@ static int __mount_install_req_dispatcher(uid_t target_uid) if (data.debug_mode) pkgmgr_client_set_debug_mode(pc, true); + if (data.skip_optimization) + pkgmgr_client_set_skip_optimization(pc, true); + if (data.tep_path[0] != '\0') pkgmgr_client_set_tep_path(pc, data.tep_path, data.tep_move); @@ -1636,6 +1648,10 @@ int main(int argc, char *argv[]) data.debug_mode = true; break; + case 'S': /* skip optimization */ + data.skip_optimization = true; + break; + /* Otherwise */ case '?': /* Not an option */ __print_usage(); -- 2.7.4 From 544e32913865e4854ac80dc44be5e8d407fbe1e3 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 22 Aug 2019 13:26:41 +0900 Subject: [PATCH 08/16] Release version 0.5.7 Changes: - Add new install option Change-Id: If14f47049250a9f6460a29fa7e88f4e5805537c7 Signed-off-by: Ilho Kim --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index d4eb399..295461b 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.5.6 +Version: 0.5.7 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From 376d88e6b5ad579e59638c4daf09c13681b6a94a Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 29 Aug 2019 17:26:53 +0900 Subject: [PATCH 09/16] Add some error log of handling backup file of preload rw pkg list Change-Id: I6c0ef27dc5a90bf007966d0e51a9ecd8884c923d Signed-off-by: Sangyoon Jang --- src/pkg_upgrade.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pkg_upgrade.c b/src/pkg_upgrade.c index 7612793..1dcddcd 100644 --- a/src/pkg_upgrade.c +++ b/src/pkg_upgrade.c @@ -164,7 +164,10 @@ static void __make_preload_rw_list(GHashTable *preload_rw_table) char tmp_path[BUF_SIZE]; snprintf(tmp_path, BUF_SIZE, "%s.tmp", ALL_PRELOAD_RW_PKG_LIST); - rename(ALL_PRELOAD_RW_PKG_LIST, tmp_path); + if (rename(ALL_PRELOAD_RW_PKG_LIST, tmp_path)) { + if (errno != ENOENT) + _LOG("can not backup preload rw pkg list: %d", errno); + } file = fopen(ALL_PRELOAD_RW_PKG_LIST, "w"); if (file == NULL) { @@ -175,7 +178,8 @@ static void __make_preload_rw_list(GHashTable *preload_rw_table) g_hash_table_foreach(preload_rw_table, __iter_cb, file); fsync(fileno(file)); fclose(file); - remove(tmp_path); + if (remove(tmp_path)) + _LOG("cannot remove backup file(%s): %d", tmp_path, errno); } static int __is_dir(const char *dirname) -- 2.7.4 From 4ffeb7113b17dd27c6701c0e69f7ec48ef7167e0 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 3 Sep 2019 15:35:56 +0900 Subject: [PATCH 10/16] Fix pkgcmd help's text, align skip-optimization option's short option is "-S" Change-Id: Idfc226ccebd93e7d95280ec205affdb95c93e9e2 Signed-off-by: Ilho Kim --- src/pkg_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index 0cca311..e710f8a 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -441,7 +441,7 @@ static void __print_usage() printf("-G, --debug-mode install the package with debug mode for sdk\n"); printf("-D, --deactivate disable package or app\n"); printf("-A, --activate enable package or app\n"); - printf("-O, --skip-optimization install the package with skip optimization for sdk\n"); + printf("-S, --skip-optimization install the package with skip optimization for sdk\n"); printf("-h, --help print this help\n"); printf("\n"); -- 2.7.4 From d1e418e2f0a302ac11903fb6f6f5e856100ac9b3 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 3 Sep 2019 15:03:07 +0900 Subject: [PATCH 11/16] Fix static analysis issue Fix null pointer dereference. Change-Id: I4088bc6a36e6f1cd936643f00ddb623af97c55dd Signed-off-by: Sangyoon Jang --- src/pkg_upgrade.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pkg_upgrade.c b/src/pkg_upgrade.c index 1dcddcd..ff9bc05 100644 --- a/src/pkg_upgrade.c +++ b/src/pkg_upgrade.c @@ -843,7 +843,16 @@ static int __find_matched_pkgid_from_list(const char *source_file, continue; version = __getvalue(buf, TOKEN_VERSION_STR, 1); + if (version == NULL) { + free(pkgid); + continue; + } pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1); + if (pkgtype == NULL) { + free(version); + free(pkgid); + continue; + } compare_result = __compare_pkgid((char *)target_file, pkgid, version, &db_update); -- 2.7.4 From d3238669e403c1b7612c570c6604ed8ae6ba2420 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 5 Sep 2019 16:31:05 +0900 Subject: [PATCH 12/16] Release version 0.5.8 Changes: - Add some error log of handling backup file of preload rw pkg list - Fix pkgcmd help's text, align - Fix static analysis issue Change-Id: I646889839d3e4a702497c59d925cc089dd8498b9 Signed-off-by: Ilho Kim --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 295461b..b375d9f 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.5.7 +Version: 0.5.8 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From 143da9090cc1595c7786239b9737cbfae7277b44 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 25 Oct 2019 16:46:48 +0900 Subject: [PATCH 13/16] Fix crash when creating delta pkg Change-Id: I91269b04a76b4b9e23fbac123514a44135bc5985 Signed-off-by: Sangyoon Jang --- src/pkg_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index e710f8a..e7e70ff 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -1298,7 +1298,7 @@ static int __create_delta_dispatcher(uid_t target_uid) return -1; } if (data.delta_pkg[0] == '\0') { - snprintf(data.resolved_path_delta_pkg, PATH_MAX, "/tmp/delta_pkg"); + data.resolved_path_delta_pkg = strdup("/tmp/delta_pkg"); printf("output file will be /tmp/delta_pkg.delta\n"); } const char *unzip_argv[] = {"sh", -- 2.7.4 From f66ff02ef1c2ae3b8d6efcf655a2cc21d846ea5f Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 29 Oct 2019 18:54:23 +0900 Subject: [PATCH 14/16] Fix code to initialize variable for every loop Without this change, previous operation type will not be initialized and it could affect next loop. Change-Id: Id514928d11b67fbc58d81a92deb3ee0506459e13 Signed-off-by: Junghyun Yeon --- src/pkg_upgrade.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkg_upgrade.c b/src/pkg_upgrade.c index ff9bc05..a5c484e 100644 --- a/src/pkg_upgrade.c +++ b/src/pkg_upgrade.c @@ -826,7 +826,7 @@ static int __find_matched_pkgid_from_list(const char *source_file, int total_pkg_cnt = 0; int compare_result = 0; - int operation = PKG_NEED_NOTHING; + int operation; bool db_update; @@ -854,6 +854,7 @@ static int __find_matched_pkgid_from_list(const char *source_file, continue; } + operation = PKG_NEED_NOTHING; compare_result = __compare_pkgid((char *)target_file, pkgid, version, &db_update); if (compare_result == PKG_IS_NOT_EXIST) { -- 2.7.4 From 0476eb97b496238552b384a97dfd39e1d986440e Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 12 Nov 2019 13:28:28 +0900 Subject: [PATCH 15/16] Release version 0.5.9 Changes: - Fix crash when creating delta pkg - Fix code to initialize variable for every loop Change-Id: I10d22e6cc7094e558219b03a7fb35c2f0cf049e9 Signed-off-by: Ilho Kim --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index b375d9f..2218e8e 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.5.8 +Version: 0.5.9 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From cc87e4c8edd4d8f76dac051c05e3ccb7c5a97f80 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Fri, 12 Jul 2019 11:11:32 +0900 Subject: [PATCH 16/16] Add upgrade script for version 30005 This version will migrate shared/data directory Change-Id: I51b58c573edf64d9d71a339f7c59ce3ff3de41e6 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 2 + data/updates/upgrade_to_30005.sh.in | 165 ++++++++++++++++++++++++++++++++++++ packaging/pkgmgr-tool.spec | 1 + 3 files changed, 168 insertions(+) create mode 100644 data/updates/upgrade_to_30005.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f688adc..a9ab2a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,3 +92,5 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/updates/upgrade_to_30003.sh.in u INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/upgrade_to_30003.sh DESTINATION /etc/package-manager/updates/) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/updates/upgrade_to_30004.sh.in upgrade_to_30004.sh $ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/upgrade_to_30004.sh DESTINATION /etc/package-manager/updates/) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/updates/upgrade_to_30005.sh.in upgrade_to_30005.sh $ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/upgrade_to_30005.sh DESTINATION /etc/package-manager/updates/) diff --git a/data/updates/upgrade_to_30005.sh.in b/data/updates/upgrade_to_30005.sh.in new file mode 100644 index 0000000..6226536 --- /dev/null +++ b/data/updates/upgrade_to_30005.sh.in @@ -0,0 +1,165 @@ +#!/bin/sh +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +source /etc/tizen-platform.conf + +PARSER_DB_NAME=.pkgmgr_parser.db +CERT_DB_NAME=.pkgmgr_cert.db +GLOBAL_PARSER_DB_PATH=$TZ_SYS_DB/$PARSER_DB_NAME +GLOBAL_CERT_DB_PATH=$TZ_SYS_DB/$CERT_DB_NAME + +SKEL_PATH=$TZ_SYS_ETC/skel/apps_rw +SHARED_DIR=.shared +SHARED_TMP_DIR=.shared_tmp +APPS_RW=apps_rw +VER_30=3.0 + +DB_RESULT_FILE=/tmp/result.log +SHAREDDATA_PRIV=http://tizen.org/privilege/appdir.shareddata + +USER_HOME_LABEL=User::Home +USER_APP_SHARED_LABEL=User::App::Shared + +function migrate_global_certdb() { + echo "PRAGMA user_version=30005;" | sqlite3 $GLOBAL_CERT_DB_PATH +} + +function create_dir() { + local target_dir=$1 + local label=$2 + + echo "#create_dir $target_dir with label $label" + mkdir $target_dir + chsmack -t -a $label $target_dir +} + +function migrate_shared_dir() { + local package=$1 + + ls $TZ_SYS_HOME | while read USERNAME + do + echo "#create shared directory for package $package, for user $USERNAME" + create_dir $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR/$package $USER_HOME_LABEL + chmod 755 $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR/$package + chown $USERNAME:users $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR/$package + + create_dir $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_TMP_DIR/$package $USER_HOME_LABEL + chmod 755 $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_TMP_DIR/$package + chown $USERNAME:users $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_TMP_DIR/$package + + mv $TZ_SYS_HOME/$USERNAME/$APPS_RW/$package/shared/data $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR/$package/ + chsmack -a $USER_APP_SHARED_LABEL $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR/$package/data + + cd $TZ_SYS_HOME/$USERNAME/$APPS_RW/$package/shared/ + ln -s ../../$SHARED_DIR/$package/data data + done + +} + +function create_skel() { + local package=$1 + + echo "#create skel for package $1" + + create_dir $SKEL_PATH/$SHARED_DIR/$package $USER_HOME_LABEL + chown root:users $SKEL_PATH/$SHARED_DIR/$package + + create_dir $SKEL_PATH/$SHARED_TMP_DIR/$package $USER_HOME_LABEL + chown root:users $SKEL_PATH/$SHARED_TMP_DIR/$package + + create_dir $SKEL_PATH/$SHARED_DIR/$package/data $USER_APP_SHARED_LABEL + chown root:system_share $SKEL_PATH/$SHARED_DIR/$package/data + chmod 4775 $SKEL_PATH/$SHARED_DIR/$package/data + + cd $SKEL_PATH/$package/shared/ + rmdir data + ln -s ../../$SHARED_DIR/$package/data data +} + +function migrate_global_pkg_shareddata() { + # for each pkg in global db, + # check whether pkg has shareddata privilege or version is less than 3.0 + echo "#migrate global pkg shareddata" + echo "SELECT DISTINCT pi.package from package_info AS pi LEFT OUTER JOIN package_privilege_info AS ppi ON pi.package=ppi.package + WHERE pi.package_api_version < $VER_30 OR ppi.privilege='$SHAREDDATA_PRIV';" | sqlite3 $GLOBAL_PARSER_DB_PATH > $DB_RESULT_FILE + while read package + do + create_skel $package + migrate_shared_dir $package + done < $DB_RESULT_FILE + rm -f $DB_RESULT_FILE + echo "PRAGMA user_version=30005;" | sqlite3 $GLOBAL_PARSER_DB_PATH +} + +function migrate_skel_shared_dir() { + create_dir $SKEL_PATH/$SHARED_DIR $USER_HOME_LABEL + chmod 755 $SKEL_PATH/$SHARED_DIR + + create_dir $SKEL_PATH/$SHARED_TMP_DIR $USER_HOME_LABEL + chmod 755 $SKEL_PATH/$SHARED_TMP_DIR +} + +function create_user_shared_dir() { + echo "#create user shared dir" + ls $TZ_SYS_HOME | while read USERNAME + do + echo "#create shared directory for $USERNAME" + create_dir $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR $USER_HOME_LABEL + chmod 755 $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR + chown $USERNAME:users $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_DIR + + create_dir $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_TMP_DIR $USER_HOME_LABEL + chmod 755 $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_TMP_DIR + chown $USERNAME:users $TZ_SYS_HOME/$USERNAME/$APPS_RW/$SHARED_TMP_DIR + done +} + +function migrate_user_pkg() { + local pkg_path=$1 + local package=$2 + + local prefix=`readlink -m "$pkg_path/../../../"` + local user_path=`readlink -m "$pkg_path/../../"` + local user_name=${user_path#$prefix/} + + local root_shared_path=`readlink -m "$pkg_path/../"` + create_dir $root_shared_path/$SHARED_DIR/$package $USER_HOME_LABEL + chmod 755 $root_shared_path/$SHARED_DIR/$package + chown $user_name:users $root_shared_path/$SHARED_DIR/$package + + mv $pkg_path/shared/data $root_shared_path/$SHARED_DIR/$package/ + cd $pkg_path/shared/ + ln -s ../../$SHARED_DIR/$package/data data + + create_dir $root_shared_path/$SHARED_TMP_DIR/$package $USER_HOME_LABEL + chmod 755 $root_shared_path/$SHARED_TMP_DIR/$package + chown $user_name:users $root_shared_path/$SHARED_TMP_DIR/$package +} + +function migrate_user_pkg_shareddata() { + echo "#migrate user pkg shareddata" + ls $TZ_SYS_DB/user | while read USERID + do + echo "SELECT DISTINCT pi.package from package_info AS pi LEFT OUTER JOIN package_privilege_info AS ppi ON pi.package=ppi.package + WHERE pi.package_api_version < $VER_30 OR ppi.privilege='$SHAREDDATA_PRIV';" | sqlite3 $TZ_SYS_DB/user/$USERID/$PARSER_DB_NAME > $DB_RESULT_FILE + while read package + do + local pkg_path=`sqlite3 $TZ_SYS_DB/user/$USERID/$PARSER_DB_NAME "SELECT root_path FROM package_info WHERE package=$package"` + migrate_user_pkg $pkg_path $package + done < $DB_RESULT_FILE + rm -f $DB_RESULT_FILE + + echo "PRAGMA user_version=30005;" | sqlite3 $TZ_SYS_DB/user/$USERID/$PARSER_DB_NAME + done +} + +rm -f $DB_RESULT_FILE + +migrate_skel_shared_dir +create_user_shared_dir + +migrate_global_pkg_shareddata + +migrate_user_pkg_shareddata + +migrate_global_certdb diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 2218e8e..ef9fe91 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -76,6 +76,7 @@ update-mime-database %{_datadir}/mime %attr(0700,root,root) /etc/package-manager/updates/upgrade_to_30002.sh %attr(0700,root,root) /etc/package-manager/updates/upgrade_to_30003.sh %attr(0700,root,root) /etc/package-manager/updates/upgrade_to_30004.sh +%attr(0700,root,root) /etc/package-manager/updates/upgrade_to_30005.sh %attr(0700,root,root) /usr/share/upgrade/scripts/701.app2sd.patch.sh %attr(0700,root,root) %{_sysconfdir}/opt/upgrade/pkgmgr.patch.sh %attr(0700,root,root) /usr/share/fixed_multiuser/scripts/pkgmgr-clear-skel.sh -- 2.7.4