static int __msc_clear_file_list(GArray *path_array);
-static int __msc_check_stop_status()
+static bool __msc_is_stop_needed()
{
if (power_off) {
- MS_DBG_ERR("Power off");
- return MS_MEDIA_ERR_SCANNER_FORCE_STOP;
- } else {
- return MS_MEDIA_ERR_NONE;
+ MS_DBG_WARN("Power off");
+ return true;
}
+
+ return false;
}
static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, const char*start_path, bool check_exists, bool is_recursive, uid_t uid)
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 };
+ char *path = NULL;
int (*scan_function)(sqlite3 *, const char*, const char*, uid_t) = NULL;
dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
- if (dir_array == NULL) {
- MS_DBG_ERR("g_array_new failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ MS_DBG_RETV_IF(dir_array == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY);
g_array_append_val(dir_array, start_path);
scan_function = (check_exists == false) ? ms_insert_item_batch : ms_validate_item;
while (dir_array->len != 0) {
- ret = __msc_check_stop_status();
- if (ret != MS_MEDIA_ERR_NONE)
+ if (__msc_is_stop_needed()) {
+ ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
goto STOP_SCAN;
+ }
current_path = g_array_index(dir_array , char*, 0);
g_array_remove_index(dir_array, 0);
}
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");
+ if (error != NULL) {
+ MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+ MS_SAFE_FREE(current_path);
+ g_error_free(error);
+ error = NULL;
+ continue;
+ }
- while ((name = g_dir_read_name(dir))) {
- ret = __msc_check_stop_status();
- if (ret != MS_MEDIA_ERR_NONE)
- goto STOP_SCAN;
+ if (ms_insert_folder(handle, storage_id, current_path, uid) != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("insert folder failed");
- if (name[0] == '.')
- continue;
+ while ((name = g_dir_read_name(dir))) {
+ if (__msc_is_stop_needed()) {
+ ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
+ goto STOP_SCAN;
+ }
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, name) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend failed");
+ if (name[0] == '.')
+ continue;
+
+ path = g_build_path(G_DIR_SEPARATOR_S, current_path, name, NULL);
+
+ if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+ /* Check symbolic link file */
+ if (g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
+ MS_DBG_WARN("Symbolic link.. Skip this file");
+ MS_SAFE_FREE(path);
continue;
}
- if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
- /* Check symbolic link file */
- if (g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
- MS_DBG_WARN("Symbolic link.. Skip this file");
- continue;
- }
+ /* Check content.scanning.others feature */
+ if (!ms_check_support_media_type(path)) {
+ MS_DBG("Unsupported media type");
+ MS_SAFE_FREE(path);
+ continue;
+ }
- /* Check content.scanning.others feature */
- if (!ms_check_support_media_type(path)) {
- MS_DBG("Unsupported media type");
- continue;
- }
+ if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("failed to update db");
- if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("failed to update db");
- continue;
- }
- } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
- if (is_recursive) {
- new_path = strdup(path);
- if (new_path != NULL) {
- g_array_append_val(dir_array, new_path);
- } else {
- MS_DBG_ERR("strdup failed");
- continue;
- }
- } else {
- if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("insert folder failed");
- }
+ MS_SAFE_FREE(path);
+ } else {
+ if (is_recursive) {
+ g_array_append_val(dir_array, path);
+ } else {
+ ms_insert_folder(handle, storage_id, path, uid);
+ MS_SAFE_FREE(path);
}
}
- } else {
- MS_DBG_ERR("g_dir_open fails [%s]", current_path);
- if (error != NULL) {
- g_error_free(error);
- error = NULL;
- }
}
+ MS_SAFE_FREE(current_path);
+
if (dir) {
g_dir_close(dir);
dir = NULL;
}
-
- MS_SAFE_FREE(current_path);
}
STOP_SCAN:
dir = NULL;
}
+ MS_SAFE_FREE(current_path);
+
__msc_clear_file_list(dir_array);
return ret;
ms_send_dir_update_noti(scan_data->msg, folder_uuid, noti_type, scan_data->pid);
}
- if (power_off) {
- MS_DBG_WARN("power off");
+ if (__msc_is_stop_needed())
goto _POWEROFF;
- }
/*disconnect from media db*/
if (handle) ms_disconnect_db(handle);
MS_SAFE_FREE(update_path);
MS_SAFE_FREE(storage_id);
- if (power_off) {
- MS_DBG_ERR("[No-Error] power off");
+ if (__msc_is_stop_needed())
goto _POWEROFF;
- }
/*disconnect from media db*/
if (handle) ms_disconnect_db(handle);
/* insert to db */
err = ms_insert_item_batch(handle, storage_id, insert_path, uid);
- if (power_off) {
- MS_DBG_ERR("power off");
+ if (__msc_is_stop_needed()) {
/*call for bundle commit*/
ms_register_end(uid);
break;
g_array_append_val(dir_array, tmp_path);
while (dir_array->len != 0) {
- ret = __msc_check_stop_status();
- if (ret != MS_MEDIA_ERR_NONE)
+ if (__msc_is_stop_needed()) {
+ ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
goto STOP_SCAN;
+ }
current_path = g_array_index(dir_array , char*, 0);
g_array_remove_index(dir_array, 0);
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();
- if (ret != MS_MEDIA_ERR_NONE)
+ if (__msc_is_stop_needed()) {
+ ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
goto STOP_SCAN;
+ }
if (name[0] == '.')
continue;
- if (ms_strappend(path, sizeof(path), "%s/%s", current_path, 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;
}
stg_info = g_array_index(storage_list, ms_stg_info_s *, idx);
/* Check power off status.. storage list vacating for g_array_free.. */
- if (power_off) {
+ if (__msc_is_stop_needed()) {
MS_SAFE_FREE(stg_info->stg_path);
MS_SAFE_FREE(stg_info->storage_id);
MS_SAFE_FREE(stg_info);
- MS_DBG_WARN("power off");
continue;
}
/*call for bundle commit*/
ms_update_end(scan_data->uid);
- if (power_off) {
- MS_DBG_WARN("power off");
+ if (__msc_is_stop_needed())
goto _POWEROFF;
- }
/*disconnect form media db*/
if (handle) ms_disconnect_db(handle);