From 13583c43e74b61ad22ee8eba832a85ad3e67dadc Mon Sep 17 00:00:00 2001 From: Sheenu Date: Wed, 6 Jan 2016 10:48:45 +0530 Subject: [PATCH] [TSAM-830] Move operation in sdcard Change-Id: I9183b01b4fc0aa41e331116c19738105746ea8bc Signed-off-by: Sheenu --- inc/mf-fo-common.h | 3 --- src/common/file-operation/mf-copy-internal.c | 29 +++++++++++++++++++++++----- src/mf-main.c | 10 ++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/inc/mf-fo-common.h b/inc/mf-fo-common.h index f6d1f7e..e9a63e8 100755 --- a/inc/mf-fo-common.h +++ b/inc/mf-fo-common.h @@ -37,9 +37,6 @@ if the file system is different, the folder size is diff, fat is 4k and fat32 is 16k*/ #define MF_ERR_BUF 256 -#define TEMP_FOLDER_FOR_COPY_PHONE "/opt/usr/media/.operation_temp" -#define TEMP_FOLDER_FOR_COPY_MMC "/opt/storage/sdcard/.operation_temp" - #define MF_FILE_ERROR_LOG(buf, fmt, arg) do { \ {\ if (strerror_r(errno, buf, MF_ERR_BUF) == 0 ) { \ diff --git a/src/common/file-operation/mf-copy-internal.c b/src/common/file-operation/mf-copy-internal.c index 9d11f44..30044b3 100755 --- a/src/common/file-operation/mf-copy-internal.c +++ b/src/common/file-operation/mf-copy-internal.c @@ -176,21 +176,26 @@ int _mf_copy_copy_regfile(const char *src, struct stat *src_statp, const char *d int location = _mf_fo_get_file_location(dst); char *copy_dst = dst; char *copy_folder = NULL; + char *root_path = NULL; if (location == MYFILE_PHONE) { copy_dst = (char *)dst; const gchar *name = g_path_get_basename(dst); - copy_folder = TEMP_FOLDER_FOR_COPY_PHONE; - dst = g_strconcat(TEMP_FOLDER_FOR_COPY_PHONE, "/", name, NULL); + storage_get_root_directory(STORAGE_TYPE_INTERNAL, &root_path); + copy_folder = g_strconcat(root_path, "/", ".operation_temp", NULL); + dst = g_strconcat(copy_folder, "/", name, NULL); } else if (location == MYFILE_MMC) { copy_dst = (char *)dst; const gchar *name = g_path_get_basename(dst); - copy_folder = TEMP_FOLDER_FOR_COPY_MMC; - dst = g_strconcat(TEMP_FOLDER_FOR_COPY_MMC, "/", name, NULL); + storage_get_root_directory(STORAGE_TYPE_EXTERNAL, &root_path); + copy_folder = g_strconcat(root_path, "/", ".operation_temp", NULL); + dst = g_strconcat(copy_folder, "/", name, NULL); } mf_error("===================== copy_dst is [%s], dst is [%s]", copy_dst, dst); if (copy_folder && !mf_file_exists(copy_folder)) { mf_mkpath(copy_folder); } + g_free(root_path); + g_free(copy_folder); dst_f = fopen(dst, "wb"); if (!dst_f) { mf_fo_loge("Fail to fopen %s file", dst); @@ -375,7 +380,6 @@ int _mf_copy_copy_regfile(const char *src, struct stat *src_statp, const char *d copy_dst = NULL; } } - return 0; ERROR_CLOSE_FD: @@ -679,6 +683,8 @@ int _mf_copy_copy_internal(const char *src, const char *dst_dir, mf_cancel *canc int alloc_size = 1; /*for null*/ struct stat src_info; char err_buf[MF_ERR_BUF] = { 0, }; + char *TEMP_FOLDER_FOR_COPY_PHONE = NULL; + char *TEMP_FOLDER_FOR_COPY_MMC = NULL; if (!src || strlen(src) <= 1) { err = MF_FO_ERR_SET(MF_FO_ERR_SRC_CLASS | MF_FO_ERR_ARGUMENT); @@ -786,6 +792,7 @@ int _mf_copy_copy_internal(const char *src, const char *dst_dir, mf_cancel *canc } } else { mf_request_type result = MF_REQ_NONE; + if (req_func) { mf_fo_request *req = mf_request_new(); if (req) { @@ -937,9 +944,15 @@ int _mf_copy_copy_internal(const char *src, const char *dst_dir, mf_cancel *canc ERROR_FREE_MEM: mf_fo_logi("Copy error"); + storage_get_root_directory(STORAGE_TYPE_INTERNAL, &TEMP_FOLDER_FOR_COPY_PHONE); + storage_get_root_directory(STORAGE_TYPE_EXTERNAL, &TEMP_FOLDER_FOR_COPY_MMC); + mf_file_recursive_rm(TEMP_FOLDER_FOR_COPY_PHONE); mf_file_recursive_rm(TEMP_FOLDER_FOR_COPY_MMC); + g_free(TEMP_FOLDER_FOR_COPY_PHONE); + g_free(TEMP_FOLDER_FOR_COPY_MMC); + SAFE_FREE(src_basename); SAFE_FREE(new_dst); @@ -948,9 +961,15 @@ ERROR_FREE_MEM: CANCEL_FREE_MEM: mf_fo_logi("Copy cancelled"); + storage_get_root_directory(STORAGE_TYPE_INTERNAL, &TEMP_FOLDER_FOR_COPY_PHONE); + storage_get_root_directory(STORAGE_TYPE_EXTERNAL, &TEMP_FOLDER_FOR_COPY_MMC); + mf_file_recursive_rm(TEMP_FOLDER_FOR_COPY_PHONE); mf_file_recursive_rm(TEMP_FOLDER_FOR_COPY_MMC); + g_free(TEMP_FOLDER_FOR_COPY_PHONE); + g_free(TEMP_FOLDER_FOR_COPY_MMC); + SAFE_FREE(new_dst); SAFE_FREE(next_name); diff --git a/src/mf-main.c b/src/mf-main.c index cef4dbd..6be77e3 100755 --- a/src/mf-main.c +++ b/src/mf-main.c @@ -302,6 +302,8 @@ __mf_main_app_init_idler_cb(void *data) assert(data); struct appdata *ap = (struct appdata *)data; char edj_path[1024] = {0}; + char *TEMP_FOLDER_FOR_COPY_PHONE = NULL; + char *TEMP_FOLDER_FOR_COPY_MMC = NULL; char *path = app_get_resource_path(); snprintf(edj_path, 1024, "%s%s/%s", path, "edje", EDJ_NAME); free(path); @@ -319,8 +321,16 @@ __mf_main_app_init_idler_cb(void *data) //mf_callback_imf_state_callback_register(ap); /*** Add the media-db update callback ***********/ media_content_set_db_updated_cb(mf_category_list_update_cb, ap); + + storage_get_root_directory(STORAGE_TYPE_INTERNAL, &TEMP_FOLDER_FOR_COPY_PHONE); + storage_get_root_directory(STORAGE_TYPE_EXTERNAL, &TEMP_FOLDER_FOR_COPY_MMC); + mf_file_recursive_rm(TEMP_FOLDER_FOR_COPY_PHONE); mf_file_recursive_rm(TEMP_FOLDER_FOR_COPY_MMC); + + g_free(TEMP_FOLDER_FOR_COPY_PHONE); + g_free(TEMP_FOLDER_FOR_COPY_MMC); + ap->mf_Status.app_init_idler = NULL; MF_TRACE_END; -- 2.7.4