From ee770dd15f18885809851c87cfe7a7c6a054d1da Mon Sep 17 00:00:00 2001 From: Sunghyun Kwon Date: Tue, 21 Jul 2015 21:11:09 +0900 Subject: [PATCH] added the init_db running logic Change-Id: I7ced32c2a1d437b7d6ed366934d93c46fa5c0b51 --- email-core/email-core-imap-idle.c | 2 +- email-core/email-storage/email-storage.c | 46 ++++++++++++++++++++++++++++++ packaging/email-service_init_db.sh | 48 +++----------------------------- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/email-core/email-core-imap-idle.c b/email-core/email-core-imap-idle.c index 77225fa..a79bc02 100755 --- a/email-core/email-core-imap-idle.c +++ b/email-core/email-core-imap-idle.c @@ -488,7 +488,7 @@ void* emcore_imap_idle_worker(void* thread_user_data) continue; } - if (g_list_length(zone_name_list) == 1) { + if (g_list_length(zone_name_list) <= 1) { if ((err = emcore_get_account_reference_list(NULL, &account_ref_list, &account_count)) != EMAIL_ERROR_NONE) EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err); diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index efc9587..85eeda1 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -1701,6 +1701,44 @@ FINISH_OFF: return ret; } +int _xsystem(const char *argv[]) +{ + int status = 0; + pid_t pid; + pid = fork(); + + switch (pid) { + case -1 : + perror("fork failed"); + return -1; + case 0 : + execvp(argv[0], (char *const *)argv); + _exit(-1); + default: + /* parent */ + break; + } + + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + return -1; + } + + if (WIFSIGNALED(status)) { + perror("signal"); + return -1; + } + + if (!WIFEXITED(status)) { + perror("should not happen"); + return -1; + } + + return WEXITSTATUS(status); +} + +#define SCRIPT_INIT_DB "/usr/bin/email-service_init_db.sh" + INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -1717,6 +1755,14 @@ INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *e return true; } + /* Generate db file */ + struct stat sts; + ret = stat(db_file_path, &sts); + if (ret == -1 && errno == ENOENT) { + const char *argv_script[] = {"/bin/sh", SCRIPT_INIT_DB, NULL}; + ret = _xsystem(argv_script); + } + EM_DEBUG_LOG("DB file path : [%s]", db_file_path); /* db open */ diff --git a/packaging/email-service_init_db.sh b/packaging/email-service_init_db.sh index 261328e..cd84cf8 100644 --- a/packaging/email-service_init_db.sh +++ b/packaging/email-service_init_db.sh @@ -2,50 +2,6 @@ source /etc/tizen-platform.conf ################################################################# -# Add preset account information -################################################################# -echo "[EMAIL-SERVICE] Start adding preset account information..." - -################################################################################################ -MP3_PATH=$TZ_USER_SHARE/settings/Alerts/Over the horizon.mp -# for active sync -vconftool set -t int db/email_handle/active_sync_handle "0" -g 6514 -s "email::vconf_active_sync_handle" - -# for default mail slot szie -vconftool set -t int db/private/email-service/slot_size "100" -g 6514 -s "email::vconf_slot_size" - -# for latest mail id -vconftool set -t int db/private/email-service/latest_mail_id "0" -g 6514 -s "email::vconf_latest_mail_id" - -# for default account id -vconftool set -t int db/private/email-service/default_account_id "0" -g 6514 -s "email::vconf_default_account_id" - -# for default account id -vconftool set -t int memory/sync/email "0" -i -g 6514 -s "email::vconf_sync_status" - -# for priority send -vconftool set -t string db/private/email-service/noti_ringtone_path "3" -g 6514 -s "email::vconf_ringtone_path" -vconftool set -t int db/private/email-service/noti_rep_type "0" -g 6514 -s "email::vconf_rep_type" -vconftool set -t bool db/private/email-service/noti_notification_ticker "0" -g 6514 -s "email::vconf_notification" -vconftool set -t bool db/private/email-service/noti_display_content_ticker "0" -g 6514 -s "email::vconf_display_content" -vconftool set -t bool db/private/email-service/noti_badge_ticker "0" -i -g 6514 -s "email::vconf_bagdge" -vconftool set -t int db/private/email-service/noti_private_id/1 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/2 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/3 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/4 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/5 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/6 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/7 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/8 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/9 "0" -i -g 6514 -vconftool set -t int db/private/email-service/noti_private_id/10 "0" -i -g 6514 -vconftool set -t bool db/private/email-service/noti_vibration_status "0" -g 6514 -s "email::vconf_vibration" -vconftool set -t bool db/private/email-service/noti_vip_vibration_status "0" -g 6514 -s "email::vconf_vip_vibration" -vconftool set -t bool db/private/email-service/noti_use_default_ringtone "1" -g 6514 -s "email::vconf_use_default_ringtone" -vconftool set -t bool db/private/email-service/noti_vip_use_default_ringtone "1" -g 6514 -s "email::vconf_vip_use_default_ringtone" - - -################################################################# # Create DB file and tables. ################################################################# echo "[EMAIL-SERVICE] Creating Email Tables ..." @@ -63,6 +19,10 @@ echo "[EMAIL-SERVICE] Finish Creating Email Tables." chmod 664 ${TZ_USER_DB}/.email-service.db chmod 664 ${TZ_USER_DB}/.email-service.db-journal +################################################################# +# Create data path +################################################################# + mkdir -m775 -p ${TZ_USER_DATA}/email/.email_data mkdir -m775 -p ${TZ_USER_DATA}/email/.email_data/tmp -- 2.7.4