#define BUF_SIZE 1024
static int __msc_check_stop_status(int scan_type, const char *start_path, int pid);
-static void __msc_clear_file_list(GArray *path_array);
-static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GArray *dir_array);
+static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array);
static int __msc_dir_scan_cb(void);
static int __msc_check_scan_same_path(char *scan_path);
static void __msc_set_storage_scan_cur_path(char *scan_path);
static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, char *start_path, int scan_type, int pid, uid_t uid)
{
- GArray *dir_array = NULL;
+ GPtrArray *dir_array = NULL;
int ret = MS_MEDIA_ERR_NONE;
char *new_path = NULL;
char *current_path = NULL;
MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
- /* make new array for storing directory */
- dir_array = g_array_new(FALSE, FALSE, sizeof(char *));
-
- /* add first direcotiry to directory array */
new_start_path = g_strdup(start_path);
- //MS_DBG_ERR("new start path [%s]", new_start_path);
- g_array_append_val(dir_array, start_path);
+ dir_array = g_ptr_array_new();
+ g_ptr_array_add(dir_array, start_path);
is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
- /* fix timing issue, folder uuid of start path mismatch in folder and media table*/
- /*if (ms_set_folder_validity(handle, storage_id, new_start_path, MS_INVALID, is_recursive, uid) != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);*/
-
if (g_file_test(new_start_path, G_FILE_TEST_IS_DIR)) {
if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("insert folder failed");
ms_batch_commit_disable(uid);
ms_batch_commit_enable(false, pid);
/* get the current path from directory array */
- current_path = g_array_index(dir_array , char*, 0);
- g_array_remove_index(dir_array, 0);
+ current_path = g_ptr_array_index(dir_array , 0);
+ g_ptr_array_remove_index(dir_array, 0);
__msc_set_dir_scan_cur_path(current_path);
/* this request is recursive scanning */
/* add new directory to dir_array */
new_path = g_strdup(path);
- g_array_append_val(dir_array, new_path);
+ g_ptr_array_add(dir_array, new_path);
if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("insert folder failed");
g_free(new_start_path);
__msc_set_dir_scan_cur_path(NULL);
- __msc_clear_file_list(dir_array);
+ g_ptr_array_free(dir_array, TRUE);
ms_batch_commit_disable(uid);
static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, char *start_path, int scan_type, int pid, uid_t uid)
{
- GArray *dir_array = NULL;
+ GPtrArray *dir_array = NULL;
int ret = MS_MEDIA_ERR_NONE;
char *new_path = NULL;
char *current_path = NULL;
MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
- /* make new array for storing directory */
- dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
-
- /* add first directory to directory array */
new_start_path = g_strdup(start_path);
- g_array_append_val(dir_array, start_path);
+ dir_array = g_ptr_array_new();
+ g_ptr_array_add(dir_array, start_path);
+
if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("insert folder failed");
ms_batch_commit_enable(false, pid);
/* get the current path from directory array */
- current_path = g_array_index(dir_array , char*, 0);
- g_array_remove_index(dir_array, 0);
+ current_path = g_ptr_array_index(dir_array, 0);
+ g_ptr_array_remove_index(dir_array, 0);
__msc_set_storage_scan_cur_path(current_path);
/* this request is recursive scanning */
/* add new directory to dir_array */
new_path = g_strdup(path);
- g_array_append_val(dir_array, new_path);
+ g_ptr_array_add(dir_array, new_path);
if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("insert folder failed");
g_free(new_start_path);
__msc_set_storage_scan_cur_path(NULL);
- __msc_clear_file_list(dir_array);
+ g_ptr_array_free(dir_array, TRUE);
ms_batch_commit_disable(uid);
return ret;
}
-static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GArray *dir_array)
+static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array)
{
int ret = MS_MEDIA_ERR_NONE;
- char *new_path = NULL;
char *current_path = NULL;
GArray *cur_dir_array = NULL;
if (ret == MS_MEDIA_ERR_NONE) {
MS_DBG_WARN("cur_dir_array->len = [%d]", cur_dir_array->len);
while (cur_dir_array->len != 0) {
- current_path = g_array_index(cur_dir_array , char*, 0);
+ current_path = g_array_index(cur_dir_array , char *, 0);
g_array_remove_index(cur_dir_array, 0);
MS_DBG_SLOG("current_path = [%s]", current_path);
- new_path = g_strdup(current_path);
- g_array_append_val(dir_array, new_path);
- g_free(current_path);
+ g_ptr_array_add(dir_array, current_path);
}
}
- __msc_clear_file_list(cur_dir_array);
+ g_array_free(cur_dir_array, FALSE);
return ret;
}
return NULL;
}
-static void __msc_clear_file_list(GArray *path_array)
-{
- if (path_array) {
- while (path_array->len != 0) {
- char *data = NULL;
- data = g_array_index(path_array , char*, 0);
- g_array_remove_index(path_array, 0);
- g_free(data);
- }
- g_array_free(path_array, FALSE);
- path_array = NULL;
- }
-}
-
static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
{
FILE *fp = NULL;