return NULL;
}
-static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
+static int __msc_make_file_list(const char *file_path, char ***path_list)
{
- FILE *fp = NULL;
- char buf[MS_FILE_PATH_LEN_MAX] = {0, };
- char *path = NULL;
- int length;
- GPtrArray *_path_array = NULL;
- int ret = MS_MEDIA_ERR_NONE;
-
- fp = fopen(file_path, "rt");
- MS_DBG_RETVM_IF(!fp, MS_MEDIA_ERR_INTERNAL, "fopen failed");
-
- _path_array = g_ptr_array_new_with_free_func(g_free);
+ char *buf = NULL;
+ GError *err = NULL;
- while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
- /* Remove '\n' */
- length = strlen(buf);
- path = g_strndup(buf, length - 1);
-
- /* check valid path */
- ret = ms_check_ignore_dir(path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_SERR("Invalid path : %s", path);
- g_free(path);
- continue;
- }
-
- g_ptr_array_add(_path_array, path);
+ if (!g_file_get_contents(file_path, &buf, NULL, &err)) {
+ MS_DBG_ERR("g_file_get_contents failed [%s]", err->message);
+ g_error_free(err);
+ return MS_MEDIA_ERR_INTERNAL;
}
- if (fp) fclose(fp);
-
- *path_array = _path_array;
+ *path_list = g_strsplit(buf, "\n", -1);
+ g_free(buf);
return MS_MEDIA_ERR_NONE;
}
-static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
+static int __msc_batch_insert(int pid, const char *request_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
- char *insert_path = NULL;
char storage_id[MS_UUID_SIZE] = {0,};
int i = 0;
+ char **path_list = NULL;
MS_DBG_FENTER();
+ ret = __msc_make_file_list(request_path, &path_list);
+ MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
+
ret = ms_connect_db(&handle, uid);
- MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_INTERNAL);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ g_strfreev(path_list);
+ return MS_MEDIA_ERR_DB_INTERNAL;
+ }
ms_register_start(true, pid);
- for (i = 0; i < path_array->len; i++) {
- insert_path = g_ptr_array_index(path_array, i);
+ for (i = 0; path_list[i][0] != '\0'; i++) {
+ ret = ms_check_ignore_dir(path_list[i], uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_SERR("Invalid path : %s", path_list[i]);
+ continue;
+ }
memset(storage_id, 0x0, MS_UUID_SIZE);
- if (ms_get_storage_id(handle, insert_path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
+ if (ms_get_storage_id(handle, path_list[i], storage_id, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("There is no storage id in media db");
continue;
}
- ret = ms_insert_item_batch(handle, storage_id, insert_path, uid);
+ ret = ms_insert_item_batch(handle, storage_id, path_list[i], uid);
if (_msc_is_power_off()) {
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
}
}
- /*call for bundle commit*/
ms_register_end(uid);
ms_disconnect_db(handle);
+ g_strfreev(path_list);
+
MS_DBG_FLEAVE();
return ret;
{
int ret = MS_MEDIA_ERR_NONE;
ms_comm_msg_s *register_data = NULL;
- GPtrArray *path_array = NULL;
while (1) {
register_data = g_async_queue_pop(reg_queue2);
+
if (register_data->pid == POWEROFF) {
MS_DBG_ERR("power off");
g_free(register_data);
}
if (register_data->msg_type == MS_MSG_BULK_INSERT) {
- ret = __msc_make_file_list(register_data->msg, &path_array, register_data->uid);
- if (ret == MS_MEDIA_ERR_NONE) {
- MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
- ret = __msc_batch_insert(register_data->pid, path_array, register_data->uid);
- g_ptr_array_free(path_array, TRUE);
- path_array = NULL;
- MS_DBG_WARN("BULK REGISTER END [%d]", ret);
- } else {
- MS_DBG_ERR("__msc_make_file_list failed [%d]", ret);
- }
+ MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
+ ret = __msc_batch_insert(register_data->pid, register_data->msg, register_data->uid);
+ MS_DBG_WARN("BULK REGISTER END [%d]", ret);
} else {
-
MS_DBG_ERR("invalid message type [%d]", register_data->msg_type);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
}
return NULL;
}
-static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
+static int __msc_make_file_list(const char *file_path, char ***path_list)
{
- FILE *fp = NULL;
- char buf[MS_FILE_PATH_LEN_MAX] = {0, };
- char *path = NULL;
- int length;
- GPtrArray *_path_array = NULL;
- int ret = MS_MEDIA_ERR_NONE;
-
- fp = fopen(file_path, "rt");
- MS_DBG_RETVM_IF(!fp, MS_MEDIA_ERR_INTERNAL, "fopen failed");
-
- _path_array = g_ptr_array_new_with_free_func(g_free);
-
- while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
- /* Remove '\n' */
- length = strlen(buf);
- path = g_strndup(buf, length - 1);
+ char *buf = NULL;
+ GError *err = NULL;
- /* check valid path */
- ret = ms_check_ignore_dir(path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_SERR("Invalid path : %s", path);
- g_free(path);
- continue;
- }
-
- g_ptr_array_add(_path_array, path);
+ if (!g_file_get_contents(file_path, &buf, NULL, &err)) {
+ MS_DBG_ERR("g_file_get_contents failed [%s]", err->message);
+ g_error_free(err);
+ return MS_MEDIA_ERR_INTERNAL;
}
- if (fp) fclose(fp);
-
- *path_array = _path_array;
+ *path_list = g_strsplit(buf, "\n", -1);
+ g_free(buf);
return MS_MEDIA_ERR_NONE;
}
-static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
+static int __msc_batch_insert(int pid, const char *request_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
- char *insert_path = NULL;
char storage_id[MS_UUID_SIZE] = {0,};
int i = 0;
+ char **path_list = NULL;
MS_DBG_FENTER();
+ ret = __msc_make_file_list(request_path, &path_list);
+ MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
+
ret = ms_connect_db(&handle, uid);
- MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_INTERNAL);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ g_strfreev(path_list);
+ return MS_MEDIA_ERR_DB_INTERNAL;
+ }
ms_register_start(true, pid);
- for (i = 0; i < path_array->len; i++) {
- insert_path = g_ptr_array_index(path_array, i);
+ for (i = 0; path_list[i][0] != '\0'; i++) {
+ ret = ms_check_ignore_dir(path_list[i], uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_SERR("Invalid path : %s", path_list[i]);
+ continue;
+ }
memset(storage_id, 0x0, MS_UUID_SIZE);
- if (ms_get_storage_id(handle, insert_path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
+ if (ms_get_storage_id(handle, path_list[i], storage_id, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("There is no storage id in media db");
continue;
}
- ret = ms_insert_item_batch(handle, storage_id, insert_path, uid);
+ ret = ms_insert_item_batch(handle, storage_id, path_list[i], uid);
if (__msc_is_power_off()) {
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
ms_register_end(uid);
ms_disconnect_db(handle);
+ g_strfreev(path_list);
+
MS_DBG_FLEAVE();
return ret;
{
int ret = MS_MEDIA_ERR_NONE;
ms_comm_msg_s *register_data = NULL;
- GPtrArray *path_array = NULL;
while (1) {
register_data = g_async_queue_pop(reg_queue);
}
if (register_data->msg_type == MS_MSG_BULK_INSERT) {
- ret = __msc_make_file_list(register_data->msg, &path_array, register_data->uid);
- if (ret == MS_MEDIA_ERR_NONE) {
- MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
- ret = __msc_batch_insert(register_data->pid, path_array, register_data->uid);
- g_ptr_array_free(path_array, TRUE);
- path_array = NULL;
- MS_DBG_WARN("BULK REGISTER END [%d]", ret);
- } else {
- MS_DBG_ERR("__msc_make_file_list failed [%d]", ret);
- }
+ MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
+ ret = __msc_batch_insert(register_data->pid, register_data->msg, register_data->uid);
+ MS_DBG_WARN("BULK REGISTER END [%d]", ret);
} else {
-
MS_DBG_ERR("invalid message type [%d]", register_data->msg_type);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
}