#define PKGID_LIST_FROM_XML_FILE \
tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, \
"pkgmgr/fota/pkgid_list_from_xml.txt")
+#define PRELOAD_RW_PKG_LIST \
+ tzplatform_mkpath(TZ_SYS_RO_APP, \
+ ".preload_rw_pkg_list")
#define DBPATH tzplatform_mkpath(TZ_SYS_DB, "/.pkgmgr_parser.db")
+#define OPT_ZIP_FILE "/usr/system/RestoreDir/opt.zip"
-#define PRELOAD_RW_TPK_PATH \
- tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-tpk")
-#define PRELOAD_RW_WGT_PATH \
- tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-wgt")
-#define PRELOAD_RW_FLAG_PATH \
- tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-flag")
-#define PRELOAD_RW_LIST_FILE \
- tzplatform_mkpath(TZ_SYS_RO_APP, \
- ".preload-rw-flag/restore_exception.list")
+static char *unzip_path[BUF_SIZE] = {
+ "opt/usr/globalapps",
+ "opt/etc/skel/apps_rw",
+ NULL
+};
float __get_elapsed_time()
{
__get_elapsed_time(), ##arg); \
} while (0)
+int remove_directory(const char *path)
+{
+ DIR *dir;
+ struct dirent *entry;
+ size_t path_len = strlen(path);
+ int ret = 0;
+ int iterate_ret;
+ char buf[BUF_SIZE] = {0};
+ size_t len;
+ struct stat statbuf;
+
+ dir = opendir(path);
+ if (!dir)
+ return -1;
+
+ while (!ret && (entry = readdir(dir))) {
+ iterate_ret = -1;
+
+ if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
+ continue;
+
+ len = path_len + strlen(entry->d_name) + 2;
+ snprintf(buf, len, "%s/%s", path, entry->d_name);
+
+ if (!stat(buf, &statbuf)) {
+ if (S_ISDIR(statbuf.st_mode))
+ iterate_ret = remove_directory(buf);
+ else
+ iterate_ret = unlink(buf);
+ }
+ ret = iterate_ret;
+ }
+
+ closedir(dir);
+ if (!ret)
+ ret = rmdir(path);
+
+ return ret;
+}
+
static int __is_dir(const char *dirname)
{
struct stat stFileInfo;
return ret;
}
-static int __compare_builtin_removable_pkgid(const char *pkgid)
-{
- retvm_if(pkgid == NULL, 0, "pkgid is null\n");
-
- int ret = 0;
- FILE *fp = NULL;
- char buf[BUF_SIZE] = {0};
-
- fp = fopen(PRELOAD_RW_LIST_FILE, "r");
- if (fp == NULL)
- return ret;
-
- while (fgets(buf, BUF_SIZE, fp) != NULL) {
- __str_trim(buf);
-
- if (strstr(buf, pkgid) != NULL) {
- _LOG("pkgid[%s] will be processed by builtin cmd.\n",
- pkgid);
- ret = -1;
- break;
- }
-
- memset(buf, 0x00, BUF_SIZE);
- }
-
- if (fp != NULL)
- fclose(fp);
-
- return ret;
-}
-
char *__manifest_to_package(const char *manifest)
{
char *package;
return package;
}
-static void __send_args_to_backend(char *pkgid, const char *pkgtype,
+static void __send_args_to_backend(const char *pkgid, const char *pkgtype,
int operation)
{
int ret = 0;
const char *new_pkgtype;
const char tpk_pkgtype[] = "tpk";
+ const char *preload_rw[] = { backend_cmd, "-y", pkgid,
+ "--preload-rw", NULL };
const char *install_ro[] = { backend_cmd, "-y", pkgid,
"--preload", "--partial-rw", NULL };
const char *uninstall_ro[] = { backend_cmd, "-d", pkgid,
"--preload", "--force-remove",
"--partial-rw", NULL };
+ const char *uninstall_ro_keeprwdata[] = { backend_cmd, "-d", pkgid,
+ "--preload", "--force-remove",
+ "--keep-rwdata", NULL };
const char *uninstall_ro_update[] = { backend_cmd, "-d",
pkgid, "--keep-rwdata", NULL };
- const char *db_update_to_normal_pkg[] = {"/usr/bin/sqlite3",
+ const char *db_cmd[] = {"/usr/bin/sqlite3",
NULL, NULL, NULL};
if (operation == PKG_NEED_NOTHING)
return;
- if (__compare_builtin_removable_pkgid(pkgid) < 0)
- return;
-
if (!strcmp(pkgtype, "rpm"))
new_pkgtype = tpk_pkgtype;
else
"package_preload='false', " \
"package_system='false' "\
"WHERE package='%s'", pkgid);
- db_update_to_normal_pkg[1] = strdup(DBPATH);
- db_update_to_normal_pkg[2] = strdup(buf);
- ret = __xsystem(db_update_to_normal_pkg);
- FREE_AND_NULL(db_update_to_normal_pkg[1]);
- FREE_AND_NULL(db_update_to_normal_pkg[2]);
+ db_cmd[1] = strdup(DBPATH);
+ db_cmd[2] = strdup(buf);
+ ret = __xsystem(db_cmd);
+ FREE_AND_NULL(db_cmd[1]);
+ FREE_AND_NULL(db_cmd[2]);
break;
case PKG_NEED_RWUNINSTALL:
case PKG_NEED_UPDATE_TO_RO:
ret = __xsystem(uninstall_ro_update);
break;
+ case PKG_NEED_RO_DBREMOVE:
+ snprintf(buf, sizeof(buf),
+ "PRAGMA foreign_keys=on; " \
+ "DELETE FROM package_info " \
+ "WHERE package='%s'", pkgid);
+ db_cmd[1] = strdup(DBPATH);
+ db_cmd[2] = strdup(buf);
+ ret = __xsystem(db_cmd);
+ FREE_AND_NULL(db_cmd[1]);
+ FREE_AND_NULL(db_cmd[2]);
+ break;
+ case PKG_NEED_PRELOADRW_INSTALL:
+ ret = __xsystem(preload_rw);
+ break;
+ case PKG_NEED_RO_UNINSTALL_KEEPRWDATA:
+ ret = __xsystem(uninstall_ro_keeprwdata);
+ break;
}
gettimeofday(&tv, NULL);
return 0;
}
+static bool __find_pkgid_from_rw_list(const char *pkgid)
+{
+ if (pkgid == NULL)
+ return false;
+
+ bool ret = false;
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ char *preload_rw_pkgid = NULL;
+
+ fp = fopen(PRELOAD_RW_PKG_LIST, "r");
+ retvm_if(fp == NULL, -1, "Failed to open : %s\n", PRELOAD_RW_PKG_LIST);
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+
+ preload_rw_pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (preload_rw_pkgid == NULL) {
+ _LOG("Failed to get pkgidstring[%s]\n", buf);
+ continue;
+ }
+
+ if (strcmp(pkgid, preload_rw_pkgid) == 0) {
+ _LOG("pkgid[%s] is converted to preload rw pkg\n", pkgid);
+ FREE_AND_NULL(preload_rw_pkgid);
+ ret = true;
+ break;
+ }
+ FREE_AND_NULL(preload_rw_pkgid);
+ }
+
+ fclose(fp);
+ return ret;
+}
+
+static int __unzip_files(char *dest_path)
+{
+ const char *unzip_argv[] = { "/usr/bin/unzip", "-oXqq",
+ OPT_ZIP_FILE, dest_path, "-d", "/", NULL };
+ int ret = __xsystem(unzip_argv);
+
+ return ret;
+}
+
+static int __install_preload_rw(const char *pkgid, const char *pkgtype)
+{
+ if (pkgid == NULL || pkgtype == NULL)
+ return -1;
+
+ int index;
+ int ret;
+ char buf[BUF_SIZE] = {0};
+
+ /* copy modified manifest */
+ snprintf(buf, BUF_SIZE, "%s/%s.xml",
+ (tzplatform_getenv(TZ_SYS_RW_PACKAGES) + 1), pkgid);
+ ret = __unzip_files(buf);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n", buf);
+ return ret;
+ }
+
+ /* copy stored signature */
+ snprintf(buf, BUF_SIZE, "%s/signatures/%s.txt",
+ (tzplatform_getenv(TZ_SYS_SHARE) + 1), pkgid);
+ ret = __unzip_files(buf);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n", buf);
+ return ret;
+ }
+
+ /* copy RO and RW components */
+ for (index = 0; index < BUF_SIZE; index++) {
+ if (unzip_path[index] == NULL)
+ break;
+
+ snprintf(buf, BUF_SIZE, "%s/%s/*", unzip_path[index], pkgid);
+ ret = __unzip_files(buf);
+ if (ret != 0) {
+ _LOG("Failed to unzip file from backup[%s]\n", buf);
+ return ret;
+ }
+ }
+
+ __send_args_to_backend(pkgid, pkgtype, PKG_NEED_PRELOADRW_INSTALL);
+ return ret;
+}
+
+static void __convert_preload_to_rw(const char *pkgid, const char *pkgtype)
+{
+ if (pkgid == NULL || pkgtype == NULL)
+ return;
+ char buf[BUF_SIZE] = {0};
+ int ret;
+
+ snprintf(buf, BUF_SIZE, "%s/skel/apps_rw/%s",
+ tzplatform_getenv(TZ_SYS_ETC), pkgid);
+
+ __send_args_to_backend(pkgid, pkgtype, PKG_NEED_RO_UNINSTALL_KEEPRWDATA);
+ ret = remove_directory(buf);
+ if (ret != 0)
+ _LOG("Failed to remove directory[%s]\n", buf);
+
+ ret = __install_preload_rw(pkgid, pkgtype);
+ if (ret != 0) {
+ _LOG("Failed install preload rw pkg[%s]\n", pkgid);
+ return;
+ }
+}
+
static int __find_deleted_pkgid_from_list(const char *source_file,
const char *target_file)
{
FILE *fp = NULL;
char buf[BUF_SIZE] = {0};
- char *pkgid = NULL;
- char *version = NULL;
+ char *pkgid;
+ char *version;
char *pkgtype = NULL;
char *update = NULL;
+ bool is_preload_rw_pkg;
bool xml_update;
int deleted_pkg_cnt = 0;
int modified_pkg_cnt = 0;
int total_pkg_cnt = 0;
-
int compare_result = 0;
fp = fopen(source_file, "r");
__str_trim(buf);
pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
- if (pkgid == NULL)
- continue;
-
version = __getvalue(buf, TOKEN_VERSION_STR, 1);
pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
+ if (pkgid == NULL || version == NULL || pkgtype == NULL) {
+ _LOG("Failed to get pkg info from string[%s]\n", buf);
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(version);
+ FREE_AND_NULL(pkgtype);
+ continue;
+ }
compare_result = __compare_pkgid((char *)target_file, pkgid,
version, &xml_update);
FREE_AND_NULL(pkgtype);
continue;
}
+
+ is_preload_rw_pkg = __find_pkgid_from_rw_list(pkgid);
+
if (!strncmp(update, "false", strlen("false"))) {
- __send_args_to_backend(pkgid, pkgtype,
- PKG_NEED_UNINSTALL);
- deleted_pkg_cnt++;
+ if (is_preload_rw_pkg) {
+ __convert_preload_to_rw(pkgid, pkgtype);
+ modified_pkg_cnt++;
+ } else {
+ __send_args_to_backend(pkgid, pkgtype,
+ PKG_NEED_UNINSTALL);
+ deleted_pkg_cnt++;
+ }
} else {
__send_args_to_backend(pkgid, pkgtype,
- PKG_NEED_UPDATE_TO_RW);
+ PKG_NEED_UPDATE_TO_RW);
modified_pkg_cnt++;
+ if (is_preload_rw_pkg) {
+ __send_args_to_backend(pkgid, pkgtype,
+ PKG_NEED_RWUNINSTALL);
+ __install_preload_rw(pkgid, pkgtype);
+ }
}
}
total_pkg_cnt++;
gettimeofday(&tv, NULL);
starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- /*check pkgmgr-fota dir, if it is not, then exit*/
- ret = __check_pkgmgr_fota_dir();
- retvm_if(ret < 0, -1, "__check_pkgmgr_fota_dir is failed.\n");
-
- /*clean pkgid list file*/
- ret = __remove_pkgid_list();
- err_if(ret < 0, "remove[%s] failed\n", FOTA_RESULT_FILE);
-
- /*get pkgid from orginal pkgmgr db*/
- ret = __get_pkgid_list_from_db_and_xml();
- retvm_if(ret < 0, -1, "__get_pkgid_list_from_db_and_xml is failed.\n");
-
- /*find deleted pkgid*/
+ /* find deleted pkgid */
ret = __find_deleted_pkgid_from_list(PKGID_LIST_FROM_DB_FILE,
PKGID_LIST_FROM_XML_FILE);
err_if(ret < 0, "__find_deleted_pkgid_from_list fail.\n");
- /*find updated, inserted pkgid*/
+ /* find updated, inserted pkgid */
ret = __find_matched_pkgid_from_list(PKGID_LIST_FROM_XML_FILE,
PKGID_LIST_FROM_DB_FILE);
err_if(ret < 0, "__find_matched_pkgid_from_list fail.\n");
return 0;
}
-static int __process_rw_fota(const char *directory, const char *pkgtype)
+static int __process_rw_fota()
{
- retvm_if(directory == NULL, -1, "directory is null\n");
-
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
int ret = -1;
- char file_path[BUF_SIZE] = {'\0'};
- DIR *dir;
- struct dirent *entry = NULL;
+ char *pkgid = NULL;
+ char *list_version = NULL;
+ char *db_stored_version = NULL;
+ char *pkgtype = NULL;
+ pkgmgrinfo_pkginfo_h handle = NULL;
+ int compare = PMINFO_VERSION_SAME;
long total_time = 0;
- char backend_cmd[BUF_SIZE];
- dir = opendir(directory);
- retvm_if(dir == NULL, -1, "Failed to access the [%s]\n", directory);
+ long starttime;
+ long endtime;
+ struct timeval tv;
_LOG("=======================================================\n");
- _LOG("RW preload package fota (%s)\n", pkgtype);
+ _LOG("RW preload package fota\n");
_LOG("=======================================================\n");
- while ((entry = readdir(dir)) != NULL) {
-
- if (entry->d_name[0] == '.') continue;
-
- snprintf(file_path, sizeof(file_path), "%s/%s", directory,
- entry->d_name);
-
- _LOG("---------------------------------------------------\n");
- _LOG(" start request : %s\n", file_path);
+ fp = fopen(PRELOAD_RW_PKG_LIST, "r");
+ retvm_if(fp == NULL, -1, "Fail get : %s\n", PRELOAD_RW_PKG_LIST);
- int compare = PMINFO_VERSION_SAME;
- long starttime;
- long endtime;
- struct timeval tv;
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
gettimeofday(&tv, NULL);
starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
- char *version = NULL;
- pkgmgrinfo_pkginfo_h handle = NULL;
- package_manager_pkg_detail_info_t *pkg_info = NULL;
-
- pkg_info = pkgmgr_client_check_pkginfo_from_file(file_path);
- if (pkg_info == NULL) {
- _LOG("can not get pkg_info from [%s]\n", file_path);
+ pkgid = __getvalue(buf, TOKEN_PKGID_STR, 1);
+ if (pkgid == NULL)
continue;
- }
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkg_info->pkgid, &handle);
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
if (ret == PMINFO_R_OK) {
- ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
- if (ret != PMINFO_R_OK) {
- _LOG("can not get pkg version[%s]\n",
- pkg_info->pkgid);
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- pkgmgr_client_free_pkginfo(pkg_info);
+ list_version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+ if (list_version == NULL) {
+ FREE_AND_NULL(pkgid);
continue;
}
-
- _LOG("pkgid = %s, db version = %s, "
- "new package version = %s\n",
- pkg_info->pkgid, version, pkg_info->version);
-
- ret = pkgmgrinfo_compare_package_version(version,
- pkg_info->version, &compare);
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &db_stored_version);
+ ret = pkgmgrinfo_compare_package_version(db_stored_version,
+ list_version, &compare);
if (ret != PMINFO_R_OK) {
- _LOG("can not compare pkg version[%s]\n",
- pkg_info->pkgid);
+ _LOG("can not compare pkg version[%s]\n", pkgid);
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- pkgmgr_client_free_pkginfo(pkg_info);
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(list_version);
continue;
}
/* package version is not update on FOTA. */
_LOG("pkg is not updated\n");
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- pkgmgr_client_free_pkginfo(pkg_info);
gettimeofday(&tv, NULL);
endtime = tv.tv_sec * 1000l +
total_time += (int)(endtime - starttime);
_LOG("finish request [time : %d ms]\n",
(int)(endtime - starttime));
+ FREE_AND_NULL(pkgid);
+ FREE_AND_NULL(list_version);
continue;
}
_LOG("pkg is updated, need to upgrade\n");
} else {
- char flag_path[BUF_SIZE] = { 0, };
- snprintf(flag_path, BUF_SIZE, "%s/%s",
- PRELOAD_RW_FLAG_PATH, pkg_info->pkgid);
- if (access(flag_path, F_OK) == 0) {
- _LOG("pkgid[%s] is installed before and "
- "uninstalled by user !! \n",
- pkg_info->pkgid);
- gettimeofday(&tv, NULL);
- endtime = tv.tv_sec * 1000l +
- tv.tv_usec / 1000l;
- total_time += (int)(endtime - starttime);
- _LOG("finish request [time : %d ms]\n",
- (int)(endtime - starttime));
- pkgmgr_client_free_pkginfo(pkg_info);
- continue;
- }
-
- _LOG("pkgid[%s] is new\n", pkg_info->pkgid);
+ _LOG("pkgid[%s] is new\n", pkgid);
}
- const char *install_rw[] = { backend_cmd, "-y",
- pkg_info->pkgid, "--preload-rw", NULL };
- snprintf(backend_cmd, sizeof(backend_cmd),
- "/usr/bin/%s-backend", pkgtype);
- ret = __xsystem(install_rw);
- if (ret == 0)
- _LOG("success request\n");
- else
- _LOG("fail request : %d\n", ret);
+ pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
+ __install_preload_rw(pkgid, pkgtype);
- if (pkg_info)
- pkgmgr_client_free_pkginfo(pkg_info);
if (handle)
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
(int)(endtime - starttime));
}
- closedir(dir);
- _LOG("=======================================================\n");
- _LOG("End RW process[time : %d ms]\n", (int)total_time);
- _LOG("=======================================================\n");
+ if (fp != NULL)
+ fclose(fp);
+
return 0;
}
{
int ret = 0;
- if (argc == 2) {
- if (strcmp(argv[1], "-rof") == 0) {
- ret = __process_ro_fota();
- retvm_if(ret < 0, EXIT_FAILURE,
- "__process_ro_fota is failed.\n");
- } else if (strcmp(argv[1], "-rwf") == 0) {
- ret = __process_rw_fota(PRELOAD_RW_TPK_PATH, "tpk");
- retvm_if(ret < 0, EXIT_FAILURE,
- "PRELOAD_RW_TPK_PATH is failed.\n");
- ret = __process_rw_fota(PRELOAD_RW_WGT_PATH, "wgt");
- retvm_if(ret < 0, EXIT_FAILURE,
- "PRELOAD_RW_WGT_PATH is failed.\n");
- } else {
- fprintf(stderr, "not supported operand\n");
- }
- } else {
- fprintf(stderr, "mising operand\n");
+ /* check pkgmgr-fota dir, if it is not, then exit */
+ ret = __check_pkgmgr_fota_dir();
+ retvm_if(ret < 0, -1, "__check_pkgmgr_fota_dir is failed.\n");
+
+ /* clean pkgid list file */
+ ret = __remove_pkgid_list();
+ err_if(ret < 0, "remove[%s] failed\n", FOTA_RESULT_FILE);
+
+ /* get pkgid from orginal pkgmgr db */
+ ret = __get_pkgid_list_from_db_and_xml();
+ retvm_if(ret < 0, -1, "__get_pkgid_list_from_db_and_xml is failed.\n");
+
+ //__get_pkginfo_from_opt();
+
+ if (argc == 1) {
+ ret = __process_ro_fota();
+ retvm_if(ret < 0, EXIT_FAILURE,
+ "__process_ro_fota is failed.\n");
+ ret = __process_rw_fota();
+ retvm_if(ret < 0, EXIT_FAILURE,
+ "__process_rw_fota is failed.\n");
+ return EXIT_SUCCESS;
}
+ if (strcmp(argv[1], "-rof") == 0) {
+ ret = __process_ro_fota();
+ retvm_if(ret < 0, EXIT_FAILURE,
+ "__process_ro_fota is failed.\n");
+ } else if (strcmp(argv[1], "-rwf") == 0) {
+ ret = __process_rw_fota();
+ retvm_if(ret < 0, EXIT_FAILURE,
+ "__process_rw_fota is failed.\n");
+ } else {
+ fprintf(stderr, "not supported operand\n");
+ }
return EXIT_SUCCESS;
}