*
*/
-#include <dirent.h> /* Defines DT_* constants */
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-
-#include <dirent.h>
#include <malloc.h>
-#include <vconf.h>
#include "media-util.h"
#include "media-server-ipc.h"
static GMutex extract_item_mutex;
-static s_extract_item* cancel_extract_item = NULL;
-static s_extract_item* cur_extract_item = NULL;
+static s_extract_item *cancel_extract_item = NULL;
+static s_extract_item *cur_extract_item = NULL;
static GCond extract_data_cond;
static GMutex extract_data_mutex;
ms_comm_msg_s *extract_data = NULL;
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
- int scan_type;
- char *storage_id = NULL;
- char *update_path = NULL;
- uid_t uid = MEDIA_DEFAULT_UID;
- ms_noti_type_e noti_type = MS_ITEM_INSERT;
while (1) {
extract_data = g_async_queue_pop(folder_extract_queue);
__msc_set_cur_extract_item(extract_data->msg, extract_data->pid);
g_directory_extract_processing = true;
- uid = extract_data->uid;
- /*connect to media db, if connecting is failed, db updating is stopped*/
- ret = ms_connect_db(&handle, uid);
+ ret = ms_connect_db(&handle, extract_data->uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_connect_db failed");
goto NEXT;
}
- scan_type = extract_data->msg_type;
- noti_type = extract_data->noti_type;
+ MS_DBG("path[%.*s] storage_id[%.*s]", MAX_MSG_SIZE, extract_data->msg, MS_UUID_SIZE, extract_data->storage_id);
- storage_id = g_strdup(extract_data->storage_id);
- if (storage_id == NULL) {
- MS_DBG_ERR("storage_id NULL");
+ if (strlen(extract_data->storage_id) == 0) {
+ MS_DBG_ERR("storage_id length is 0");
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- MS_DBG("path : [%.*s], storage_id : [%s]", MAX_MSG_SIZE, extract_data->msg, storage_id);
-
- update_path = g_strdup(extract_data->msg);
-
- if (strlen(storage_id) == 0) {
- MS_DBG_ERR("storage_id length is 0. There is no information of your request [%.*s]", MAX_MSG_SIZE, extract_data->msg);
+ if (strlen(extract_data->msg) == 0) {
+ MS_DBG_ERR("path length is 0");
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- if (scan_type != MS_MSG_DIRECTORY_SCANNING
- && scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+ if (extract_data->msg_type != MS_MSG_DIRECTORY_SCANNING &&
+ extract_data->msg_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
MS_DBG_ERR("Invalid request");
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid);
-
+ ret = __msc_check_extract_stop_status(extract_data->msg_type, extract_data->msg, extract_data->pid);
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP");
goto NEXT;
}
- /*insert data into media db */
- ret = msc_check_db_size(uid, extract_data->msg_type);
+ ret = msc_check_db_size(extract_data->uid, extract_data->msg_type);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("NOT ENOUGH MEMORY");
if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
goto NEXT;
}
- ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, update_path, scan_type, extract_data->pid);
+ ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, extract_data->msg, extract_data->msg_type, extract_data->pid);
NEXT:
g_directory_extract_processing = false;
if (_msc_is_power_off())
goto _POWEROFF;
- /*Active flush */
malloc_trim(0);
if (extract_data->result) {
MS_DBG_ERR("MS_MSG_SCANNER_COMPLETE");
- if (noti_type == MS_ITEM_INSERT || noti_type == MS_ITEM_UPDATE) {
- /*send notification*/
+ if (extract_data->noti_type == MS_ITEM_INSERT || extract_data->noti_type == MS_ITEM_UPDATE) {
char *folder_uuid = NULL;
- ms_get_folder_id(handle, storage_id, extract_data->msg, &folder_uuid);
- MS_DBG_WARN("storage_id = [%s], dir Path = [%s], folder_uuid = [%s], noti_type = [%d]", storage_id, update_path, folder_uuid, noti_type);
- ms_send_dir_update_noti(update_path, folder_uuid, noti_type, extract_data->pid);
+ ms_get_folder_id(handle, extract_data->storage_id, extract_data->msg, &folder_uuid);
+ MS_DBG_WARN("storage_id[%.*s] Path[%.*s] folder_id[%s] noti_type[%d]", MS_UUID_SIZE, extract_data->storage_id, MAX_MSG_SIZE, extract_data->msg, folder_uuid, extract_data->noti_type);
+ ms_send_dir_update_noti(extract_data->msg, folder_uuid, extract_data->noti_type, extract_data->pid);
}
extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
msc_send_result(ret, extract_data);
msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, extract_data->pid, extract_data->msg);
}
- g_free(update_path);
- update_path = NULL;
g_free(extract_data);
extract_data = NULL;
- g_free(storage_id);
- storage_id = NULL;
__msc_del_cur_extract_item();
__msc_del_cancel_extract_item();
ms_storage_scan_status_e storage_scan_status = MS_STORAGE_SCAN_NONE;
__msc_get_storage_extract_status(&storage_scan_status);
- /*get storage list and scan status from media db*/
if (storage_scan_status != MS_STORAGE_SCAN_COMPLETE) {
__msc_resume_extract();
MS_DBG_WARN("extract RESUME OK");
}
- /*disconnect form media db*/
ms_disconnect_db(handle);
usleep(SCAN_SLEEP_TIME);
- } /*thread while*/
+ }
_POWEROFF:
__msc_resume_extract();
- g_free(update_path);
g_free(extract_data);
- g_free(storage_id);
ms_disconnect_db(handle);
return NULL;
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
- int scan_type;
- char *update_path = NULL;
- uid_t uid = MEDIA_DEFAULT_UID;
- int tem_ret = MS_MEDIA_ERR_NONE;
while (1) {
__msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
MS_DBG_WARN("STORAGE extract START extract len is %d ", g_async_queue_length(storage_extract_queue));
- scan_type = extract_data->msg_type;
- if (scan_type != MS_MSG_STORAGE_ALL
- && scan_type != MS_MSG_STORAGE_PARTIAL) {
- MS_DBG_ERR("Invalid request[%d]", scan_type);
+ if (extract_data->msg_type != MS_MSG_STORAGE_ALL && extract_data->msg_type != MS_MSG_STORAGE_PARTIAL) {
+ MS_DBG_ERR("Invalid request[%d]", extract_data->msg_type);
msc_remove_extract_request(extract_data);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- uid = extract_data->uid;
-
- /*connect to media db, if connecting is failed, db updating is stopped*/
- ret = ms_connect_db(&handle, uid);
+ ret = ms_connect_db(&handle, extract_data->uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_connect_db falied!");
continue;
}
- update_path = g_strdup(extract_data->msg);
- if (!MS_STRING_VALID(update_path)) {
- MS_DBG_ERR("Invalid update_path");
+ MS_DBG("path[%.*s] storage_id[%.*s]", MAX_MSG_SIZE, extract_data->msg, MS_UUID_SIZE, extract_data->storage_id);
+
+ if (strlen(extract_data->storage_id) == 0) {
+ MS_DBG_ERR("storage_id length is 0");
+ ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ goto NEXT;
+ }
+
+ if (strlen(extract_data->msg) == 0) {
+ MS_DBG_ERR("path length is 0");
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- MS_DBG_WARN("extract storage_id is [%s], path [%s]", extract_data->storage_id, update_path);
- ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
+
+ ret = ms_user_get_storage_type(extract_data->uid, extract_data->msg, &storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_user_get_storage_type failed");
goto NEXT;
}
if (storage_type == MS_USER_STORAGE_EXTERNAL_USB) {
- if (!ms_storage_mount_status(update_path)) {
- MS_DBG_ERR("%s is unmounted", update_path);
+ if (!ms_storage_mount_status(extract_data->msg)) {
+ MS_DBG_ERR("%s is unmounted", extract_data->msg);
ret = MS_MEDIA_ERR_USB_UNMOUNTED;
msc_remove_extract_request(extract_data);
goto NEXT;
}
}
- ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, uid);
+ ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, extract_data->uid);
__msc_extract_set_db_status(MS_DB_UPDATING);
- ret = msc_check_db_size(uid, extract_data->msg_type);
+ ret = msc_check_db_size(extract_data->uid, extract_data->msg_type);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("NOT ENOUGH MEMORY");
__msc_extract_set_db_status(MS_DB_STOPPED);
}
/*extract meta*/
- ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, update_path, scan_type, extract_data->pid);
+ ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, extract_data->msg, extract_data->msg_type, extract_data->pid);
MS_DBG_WARN("extract PAUSE");
__msc_pause_extract();
MS_DBG_WARN("extract RESUME");
- tem_ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid);
- if (tem_ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
- ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_STOP, uid);
+ if (__msc_check_extract_stop_status(extract_data->msg_type, extract_data->msg, extract_data->pid) == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
+ ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_STOP, extract_data->uid);
__msc_set_storage_extract_status(MS_STORAGE_SCAN_META_STOP);
MS_DBG_WARN("storage scan force stopped");
/* set vconf key db extract status */
if (extract_data->result) {
MS_DBG_WARN("extract_data->result is true, MS_STORAGE_SCAN_COMPLETE");
- __msc_del_extract_blocked_path(update_path);
- ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, uid);
+ __msc_del_extract_blocked_path(extract_data->msg);
+ ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, extract_data->uid);
__msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
- /* send notification */
- ms_send_dir_update_noti(update_path, NULL, MS_ITEM_UPDATE, extract_data->pid);
- /* set vconf key db extract status */
+ ms_send_dir_update_noti(extract_data->msg, NULL, MS_ITEM_UPDATE, extract_data->pid);
__msc_extract_set_db_status(MS_DB_UPDATED);
}
NEXT:
- g_free(update_path);
- update_path = NULL;
-
if (_msc_is_power_off())
goto _POWEROFF;
static int __msc_extract_set_db_status(ms_db_status_type_t status)
{
int res = MS_MEDIA_ERR_NONE;
- //int err = 0;
if (!ms_config_set_int(VCONFKEY_PRIVATE_EXTRACTSTATUS, status)) {
res = MS_MEDIA_ERR_INTERNAL;