#include "media-scanner-socket.h"
#include "media-scanner-scan.h"
-typedef struct msc_scan_data {
- char *name;
- struct msc_scan_data *next;
-} msc_scan_data;
-
bool power_off;
GAsyncQueue * storage_queue;
GAsyncQueue *scan_queue;
char *g_cancel_path;
char *g_blocked_path;
bool g_directory_scan_processing;
-GArray *blocked_stg_list;
-
int stg_scan_status;
static int __msc_check_stop_status(ms_storage_type_t storage_type);
static int __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_set_storage_scan_status(ms_storage_scan_status_e status);
-//static int __msc_get_storage_scan_status(ms_storage_scan_status_e *status, uid_t uid);
-
-#if 0
-GCond data_cond;
-GMutex data_mutex;
-gpointer current_data = NULL;
-
-static int __msc_resume_scan()
-{
- g_mutex_lock(&data_mutex);
-
-// current_data = GINT_TO_POINTER(g_directory_scan_processing);
- g_cond_signal(&data_cond);
-
- g_mutex_unlock(&data_mutex);
-
- return MS_MEDIA_ERR_NONE;
-}
-static int __msc_pause_scan()
-{
- g_mutex_lock(&data_mutex);
-
-// while (current_data)
- while (g_directory_scan_processing)
- g_cond_wait(&data_cond, &data_mutex);
-
-// current_data = GPOINTER_TO_INT(g_directory_scan_processing);
-
- g_mutex_unlock(&data_mutex);
-
- return MS_MEDIA_ERR_NONE;
-}
-#endif
static int __msc_check_stop_status(ms_storage_type_t storage_type)
{
int ret = MS_MEDIA_ERR_NONE;
- /*check poweroff status*/
if (power_off) {
MS_DBG_ERR("Power off");
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
return ret;
}
-static bool __msc_check_mount_storage(const char* start_path)
+static int __msc_read_dir(void **handle, const char *start_path, const char *storage_id, ms_storage_type_t storage_type, int scan_type, uid_t uid)
{
- bool ret = FALSE;
- DIR *dp = NULL;
-
- dp = opendir(start_path);
-
- if (dp != NULL) {
- ret = TRUE;
- closedir(dp);
- MS_DBG_WARN("STORAGE IS MOUNTED[%s]", start_path);
- }
-
- return ret;
-}
-
-static int __msc_read_dir(void **handle, GArray *dir_array, const char *start_path, const char *storage_id, ms_storage_type_t storage_type, int scan_type, uid_t uid)
-{
- DIR *dp = NULL;
- struct dirent entry;
- struct dirent *result = NULL;
int ret = MS_MEDIA_ERR_NONE;
+ GDir *dir = NULL;
+ GError *error = NULL;
+ const char *name;
+ GArray *dir_array = NULL;
char *new_path = NULL;
char *current_path = NULL;
char path[MS_FILE_PATH_LEN_MAX] = { 0 };
int (*scan_function)(void **, const char*, const char*, uid_t) = NULL;
- if (dir_array != NULL) {
- MS_DBG_ERR("dir_array is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- /* make new array for storing directory */
dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
if (dir_array == NULL) {
MS_DBG_ERR("g_array_new failed");
scan_function = (scan_type == MS_MSG_STORAGE_ALL) ? ms_insert_item_batch : ms_validate_item;
- /*start db update. the number of element in the array , db update is complete.*/
while (dir_array->len != 0) {
- /*check poweroff status*/
ret = __msc_check_stop_status(storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
goto STOP_DIR_SCAN;
}
- /* get the current path from directory array */
+
current_path = g_array_index(dir_array , char*, 0);
g_array_remove_index(dir_array, 0);
MS_DBG_SLOG("%d", dir_array->len);
ms_insert_folder_start(handle);
- dp = opendir(current_path);
- if (dp != NULL) {
- /*insert current directory*/
+ dir = g_dir_open(current_path, 0, &error);
+ if (error == NULL && dir != NULL) {
if (ms_insert_folder(handle, storage_id, current_path, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("insert folder failed");
}
-
- while (!readdir_r(dp, &entry, &result)) {
- /*check poweroff status*/
+ while ((name = g_dir_read_name(dir))) {
ret = __msc_check_stop_status(storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
ms_insert_folder_end(handle, uid);
goto STOP_DIR_SCAN;
}
- if (result == NULL)
- break;
-
- if (entry.d_name[0] == '.')
+ if (name[0] == '.')
continue;
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+ if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_strappend failed");
continue;
}
- if (entry.d_type & DT_REG) {
- /* insert into media DB */
+ if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("failed to update db : %d", scan_type);
continue;
}
- } else if (entry.d_type & DT_DIR) {
+ } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
- /* this request is recursive scanning */
- /* add new directory to dir_array */
new_path = strdup(path);
if (new_path != NULL) {
g_array_append_val(dir_array, new_path);
continue;
}
} else {
- /* this request is recursive scanning */
- /* don't add new directory to dir_array */
if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("insert folder failed");
}
}
}
} else {
- MS_DBG_ERR("%s folder opendir fails", current_path);
+ MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+ }
+
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
}
- if (dp) closedir(dp);
- dp = NULL;
ms_insert_folder_end(handle, uid);
}
STOP_DIR_SCAN:
- if (dp) closedir(dp);
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
+ }
+
__msc_clear_file_list(dir_array);
return ret;
-
}
static int __msc_dir_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, bool is_recursive, uid_t uid)
{
- GArray *dir_array = NULL;
int ret = MS_MEDIA_ERR_NONE;
- /*call for bundle commit*/
ms_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, 0);
- __msc_read_dir(handle, dir_array, start_path, storage_id, storage_type, scan_type, uid);
+ ret = __msc_read_dir(handle, start_path, storage_id, storage_type, scan_type, uid);
- /*call for bundle commit*/
ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
-
MS_DBG_INFO("ret : %d", ret);
return ret;
}
-
static int __msc_stg_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid)
{
- DIR *dp = NULL;
- GArray *dir_array = NULL;
- struct dirent entry;
- struct dirent *result = NULL;
int ret = MS_MEDIA_ERR_NONE;
+ GDir *dir = NULL;
+ GError *error = NULL;
+ const char *name;
+ GArray *dir_array = NULL;
char *new_path = NULL;
char *current_path = NULL;
char path[MS_FILE_PATH_LEN_MAX] = { 0 };
}
}
- if (ms_check_folder_path(new_start_path)) {
+ if (g_file_test(new_start_path, G_FILE_TEST_IS_DIR)) {
ms_insert_folder(handle, storage_id, new_start_path, uid);
}
ms_insert_folder_start(handle);
- dp = opendir(current_path);
- if (dp != NULL) {
- while (!readdir_r(dp, &entry, &result)) {
+ dir = g_dir_open(current_path, 0, &error);
+ if (error == NULL && dir != NULL) {
+ while ((name = g_dir_read_name(dir))) {
/*check poweroff status*/
ret = __msc_check_stop_status(storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
goto STOP_SCAN;
}
- if (result == NULL)
- break;
-
- if (entry.d_name[0] == '.')
+ if (name[0] == '.')
continue;
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+ if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_strappend failed");
continue;
}
- if (entry.d_type & DT_REG) {
- /* insert into media DB */
+ if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("failed to update db : %d", scan_type);
continue;
}
- } else if (entry.d_type & DT_DIR) {
+ } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
- /* this request is recursive scanning */
- /* add new directory to dir_array */
new_path = strdup(path);
if (new_path != NULL) {
g_array_append_val(dir_array, new_path);
continue;
}
} else {
- /* this request is recursive scanning */
- /* don't add new directory to dir_array */
if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("insert folder failed");
continue;
}
}
}
- /* update modified time of directory */
if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE && storage_type == MS_STORAGE_INTERNAL)
ms_update_folder_time(handle, INTERNAL_STORAGE_ID, current_path, uid);
} else {
- MS_DBG_ERR("%s folder opendir fails", current_path);
+ MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+ }
+
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
}
- if (dp) closedir(dp);
- dp = NULL;
ms_insert_folder_end(handle, uid);
MS_SAFE_FREE(current_path);
} /*db update while */
- /*remove invalid folder in folder table.*/
- if (__msc_check_mount_storage(start_path)) {
+ /*remove invalid folder in folder table.*/
+ if (g_file_test(start_path, G_FILE_TEST_IS_DIR)) {
if (ms_delete_invalid_folder(handle, storage_id, storage_type, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("delete invalid folder failed");
ret = MS_MEDIA_ERR_DB_DELETE_FAIL;
}
STOP_SCAN:
- if (dp) closedir(dp);
- dp = NULL;
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
+ }
__msc_clear_file_list(dir_array);
scan_type = scan_data->msg_type;
start_path = strndup(scan_data->msg, scan_data->msg_size);
- /*if scan type is not MS_SCAN_NONE, check data in db. */
if (scan_type != MS_MSG_STORAGE_INVALID) {
MS_DBG_INFO("INSERT");
if (err != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("error : %d", err);
}
- } else if (scan_type == MS_MSG_STORAGE_INVALID) {
+ } else {
MS_DBG_INFO("INVALID");
- /*In this case, update just validation record*/
- /*update just valid type*/
err = ms_validaty_change_all_items(handle, storage_id, storage_type, false, scan_data->uid);
if (err != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("error : %d", err);
MS_DBG_WARN("DIRECTORY SCAN START [%s %d]", scan_data->msg, scan_data->msg_type);
- /*connect to media db, if conneting is failed, db updating is stopped*/
ret = ms_connect_db(&handle, scan_data->uid);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_connect_db failed");
scan_type = scan_data->msg_type;
if (strlen(scan_data->storage_id) > 0) {
- /*MS_DBG("path : [%s], storage_id : [%s]", scan_data->msg, scan_data->storage_id);*/
- storage_id = strdup(scan_data->storage_id);
+ storage_id = g_strdup(scan_data->storage_id);
+ if (storage_id == NULL) {
+ MS_DBG_ERR("storage_id NULL");
+ ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ goto NEXT;
+ }
} else {
MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", scan_data->msg);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
- if (storage_id == NULL) {
- MS_DBG_ERR("storage_id NULL");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- goto NEXT;
- }
-
MS_DBG("path : [%s], storage_id : [%s]", scan_data->msg, storage_id);
- if (strlen(storage_id) == 0) {
- MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", scan_data->msg);
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- goto NEXT;
- }
-
if (scan_type != MS_MSG_DIRECTORY_SCANNING
&& scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
MS_DBG_ERR("Invalid request");
ms_trim_dir_path(scan_data->msg);
- if (ms_check_folder_path(scan_data->msg)) {
+ if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) {
is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
static int __msc_compare_with_db(void **handle, const char *storage_id, const char*update_path, int scan_type, GArray **dir_array)
{
- DIR *dp = NULL;
- GArray *read_dir_array = NULL;
- struct dirent entry;
- struct dirent *result = NULL;
int ret = MS_MEDIA_ERR_NONE;
+ GDir *dir = NULL;
+ GError *error = NULL;
+ const char *name;
+ GArray *read_dir_array = NULL;
char *new_path = NULL;
char *current_path = NULL;
char path[MS_FILE_PATH_LEN_MAX] = { 0 };
/* get the current path from directory array */
current_path = g_array_index(read_dir_array , char*, 0);
g_array_remove_index(read_dir_array, 0);
-// MS_DBG_ERR("%s", current_path);
if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("%s is ignore", current_path);
continue;
}
- dp = opendir(current_path);
- if (dp != NULL) {
- while (!readdir_r(dp, &entry, &result)) {
- if (result == NULL)
- break;
+ dir = g_dir_open(current_path, 0, &error);
+ if (error == NULL && dir != NULL) {
+ while ((name = g_dir_read_name(dir))) {
+ if (name[0] == '.') {
+ continue;
+ }
- if (entry.d_name[0] == '.') {
+ if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_strappend failed");
continue;
}
- if (entry.d_type & DT_DIR) {
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend failed");
- continue;
- }
+ if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
/* add new directory to dir_array */
new_path = strdup(path);
g_array_append_val(read_dir_array, new_path);
- } else if (entry.d_type & DT_REG) {
+ } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
item_num++;
}
}
_check_folder_from_list(current_path, item_num, *dir_array);
item_num = 0;
} else {
- MS_DBG_ERR("%s folder opendir fails", current_path);
+ MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+ }
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
}
- if (dp) closedir(dp);
- dp = NULL;
+
MS_SAFE_FREE(current_path);
} /*db update while */
dir_info = g_array_index(dir_array, ms_dir_info_s*, i);
update_path = strdup(dir_info->dir_path);
-// MS_DBG_SLOG("update_path : %s, %d", update_path, dir_info->modified_time);
if (dir_info->modified_time != -1) {
err = ms_set_folder_item_validity(handle, storage_id, update_path, MS_INVALID, MS_NON_RECURSIVE, uid);
if (err != MS_MEDIA_ERR_NONE) {
__msc_stg_scan(handle, storage_id, update_path, storage_type, MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, uid);
-// if (dir_info->modified_time != -1) {
-// ms_update_folder_time(handle, tmp_path);
-// }
MS_SAFE_FREE(update_path);
}
static int __msc_dir_scan_meta_update(void **handle, const char*start_path, const char *storage_id, ms_storage_type_t storage_type, uid_t uid)
{
- DIR *dp = NULL;
- GArray *dir_array = NULL;
- struct dirent entry;
- struct dirent *result = NULL;
int ret = MS_MEDIA_ERR_NONE;
+ GDir *dir = NULL;
+ GError *error = NULL;
+ const char *name;
+ GArray *dir_array = NULL;
char *new_path = NULL;
char *current_path = NULL;
char *tmp_path = NULL;
continue;
}
- dp = opendir(current_path);
- if (dp != NULL) {
- while (!readdir_r(dp, &entry, &result)) {
- /*check poweroff status*/
+ dir = g_dir_open(current_path, 0, &error);
+ if (error == NULL && dir != NULL) {
+ while ((name = g_dir_read_name(dir))) {
ret = __msc_check_stop_status(storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
goto STOP_SCAN;
}
- if (result == NULL)
- break;
-
- if (entry.d_name[0] == '.')
+ if (name[0] == '.')
continue;
- if (entry.d_type & DT_REG) {
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend failed");
- continue;
- }
+ if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_strappend failed");
+ continue;
+ }
- /* insert into media DB */
- MS_DBG_WARN("%s", path);
+ if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
if (scan_function(handle, path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("failed to update db");
continue;
}
- } else if (entry.d_type & DT_DIR) {
- /* this request is recursive scanning */
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend failed");
- continue;
- }
- /* add new directory to dir_array */
+ } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
new_path = strdup(path);
g_array_append_val(dir_array, new_path);
}
MS_DBG_ERR("%s folder opendir fails", current_path);
}
- if (dp) closedir(dp);
- dp = NULL;
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
+ }
+
MS_SAFE_FREE(current_path);
} /*db update while */
STOP_SCAN:
- if (dp) closedir(dp);
+ if (dir) {
+ g_dir_close(dir);
+ dir = NULL;
+ }
__msc_clear_file_list(dir_array);