#define BUF_SIZE 1024
static int __msc_check_stop_status(int scan_type, const char *start_path, int pid);
-static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid);
-static int __msc_batch_insert(int pid, GArray *path_array, uid_t uid);
static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data);
static void __msc_clear_file_list(GArray *path_array);
static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
}
}
-static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid)
+static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
{
FILE *fp = NULL;
- char buf[MS_FILE_PATH_LEN_MAX] = {0,};
+ char buf[MS_FILE_PATH_LEN_MAX] = {0, };
char *path = NULL;
int length;
- int res = MS_MEDIA_ERR_NONE;
+ GPtrArray *_path_array = NULL;
int ret = MS_MEDIA_ERR_NONE;
- /* load the file list from file */
fp = fopen(file_path, "rt");
- if (fp == NULL) {
- MS_DBG_STRERROR("fopen failed");
- res = MS_MEDIA_ERR_INTERNAL;
- goto FREE_RESOURCE;
- }
+ MS_DBG_RETVM_IF(!fp, MS_MEDIA_ERR_INTERNAL, "fopen failed");
- memset(buf, 0x0, MS_FILE_PATH_LEN_MAX);
- /* This is an array for storing the path of insert datas*/
- *path_array = g_array_new(FALSE, FALSE, sizeof(char *));
+ _path_array = g_ptr_array_new_with_free_func(g_free);
- /* read registering file path from stored file */
while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
- length = strlen(buf); /*the return value of function, strlen(), includes "\n" */
- path = g_strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
+ /* Remove '\n' */
+ length = strlen(buf);
+ path = g_strndup(buf, length - 1);
/* check valid path */
ret = ms_check_ignore_dir(path, uid);
g_free(path);
continue;
}
- /* insert getted path to the list */
- g_array_append_val(*path_array, path);
+
+ g_ptr_array_add(_path_array, path);
}
if (fp) fclose(fp);
- fp = NULL;
-
- return MS_MEDIA_ERR_NONE;
-
-FREE_RESOURCE:
- __msc_clear_file_list(*path_array);
+ *path_array = _path_array;
- if (fp) fclose(fp);
- fp = NULL;
-
- return res;
+ return MS_MEDIA_ERR_NONE;
}
-static int __msc_batch_insert(int pid, GArray *path_array, uid_t uid)
+static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
{
- int err;
- unsigned int i;
+ int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
char *insert_path = NULL;
char storage_id[MS_UUID_SIZE] = {0,};
+ int i = 0;
- /* connect to media db, if conneting is failed, db updating is stopped */
- err = ms_connect_db(&handle, uid);
- if (err != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_DB_INTERNAL;
+ MS_DBG_FENTER();
- /*start db updating */
- /*call for bundle commit*/
- ms_batch_commit_enable(true, pid);
+ ret = ms_connect_db(&handle, uid);
+ MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_INTERNAL);
- MS_DBG_WARN("BULK REGISTER START");
+ ms_batch_commit_enable(true, pid);
- /* get the inserting file path from array and insert to db */
for (i = 0; i < path_array->len; i++) {
+ insert_path = g_ptr_array_index(path_array, i);
- insert_path = g_array_index(path_array, char*, i);
-
- /* get storage list */
memset(storage_id, 0x0, MS_UUID_SIZE);
- if (ms_get_storage_id(handle, insert_path, storage_id, uid) < 0) {
+ if (ms_get_storage_id(handle, insert_path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("There is no storage id in media db");
continue;
}
- /* insert to db */
- err = ms_insert_item_batch(handle, storage_id, insert_path, uid);
+ ret = ms_insert_item_batch(handle, storage_id, insert_path, uid);
if (_msc_is_power_off()) {
- /*call for bundle commit*/
+ ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
break;
}
}
/*call for bundle commit*/
ms_batch_commit_disable(uid);
-
- /*disconnect form media db*/
ms_disconnect_db(handle);
- return MS_MEDIA_ERR_NONE;
+ MS_DBG_FLEAVE();
+
+ return ret;
}
static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data)
{
ms_comm_msg_s *register_data = NULL;
GArray *register_array = NULL;
- GArray *path_array = NULL;
+ GPtrArray *path_array = NULL;
char *file_path = NULL;
int ret;
int pid = 0;
MS_DBG_WARN("BULK REGISTER END [%d |%.*s]", ret, MAX_MSG_SIZE, register_data->msg);
- __msc_clear_file_list(path_array);
+ g_ptr_array_free(path_array, TRUE);
+ path_array = NULL;
g_free(file_path);
file_path = NULL;
register_array = NULL;
}
- __msc_clear_file_list(path_array);
-
return NULL;
}