*/
#include <malloc.h>
+#include <dirent.h>
#include "media-util.h"
#include "media-server-ipc.h"
int scan_count = 0;
int sleep_count = 0;
- GDir *dir = NULL;
- GError *error = NULL;
- const char *name;
+ DIR *dir = NULL;
+ struct dirent64 *dir_entry = NULL;
MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
sleep_count = 0;
- dir = g_dir_open(current_path, 0, &error);
- if (error != NULL) {
+ dir = opendir(current_path);
+ if (dir == 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))) {
+ while ((dir_entry = readdir64(dir))) {
sleep_count++;
- if (sleep_count % 5 == 0) {
+ if (sleep_count % SCAN_SLEEP_FILECOUNT == 0) {
sleep_count = 0;
usleep(SCAN_SLEEP_TIME);
}
goto STOP_SCAN;
}
- if (name[0] == '.')
+ if (dir_entry->d_name[0] == '.')
continue;
- if (strcmp(name, RECYCLE_DIR_NAME) == 0)
+ if (strcmp(dir_entry->d_name, RECYCLE_DIR_NAME) == 0)
continue;
- if (g_snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, name) >= MS_FILE_PATH_LEN_MAX) {
+ if (g_snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, dir_entry->d_name) >= MS_FILE_PATH_LEN_MAX) {
MS_DBG_ERR("g_snprintf failed");
continue;
}
- if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+ if (dir_entry->d_type == DT_REG) {
if (!ms_check_support_media_type(path))
continue;
}
}
}
- } else {
+ } else if (dir_entry->d_type == DT_DIR) {
if (msg_type == MS_MSG_DIRECTORY_SCANNING) {
new_path = g_strdup(path);
g_ptr_array_add(dir_array, new_path);
MS_SAFE_FREE(current_path);
if (dir) {
- g_dir_close(dir);
+ closedir(dir);
dir = NULL;
}
END_SCAN:
if (dir) {
- g_dir_close(dir);
+ closedir(dir);
dir = NULL;
}
int scan_count = 0;
int sleep_count = 0;
- GDir *dir = NULL;
- GError *error = NULL;
- const char *name;
+ DIR *dir = NULL;
+ struct dirent64 *dir_entry = NULL;
bool is_missing = false;
ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
sleep_count = 0;
- dir = g_dir_open(current_path, 0, &error);
- if (error != NULL) {
+ dir = opendir(current_path);
+ if (dir == 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))) {
+ while ((dir_entry = readdir64(dir))) {
sleep_count++;
- if (sleep_count % 5 == 0) {
+ if (sleep_count % SCAN_SLEEP_FILECOUNT == 0) {
sleep_count = 0;
usleep(SCAN_SLEEP_TIME);
}
if (ret != MS_MEDIA_ERR_NONE)
goto STOP_SCAN;
- if (name[0] == '.')
+ if (dir_entry->d_name[0] == '.')
continue;
- if (strcmp(name, RECYCLE_DIR_NAME) == 0)
+ if (strcmp(dir_entry->d_name, RECYCLE_DIR_NAME) == 0)
continue;
- if (g_snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, name) >= MS_FILE_PATH_LEN_MAX) {
+ if (g_snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, dir_entry->d_name) >= MS_FILE_PATH_LEN_MAX) {
MS_DBG_ERR("g_snprintf failed");
continue;
}
- if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+ if (dir_entry->d_type == DT_REG) {
if (!ms_check_support_media_type(path))
continue;
msc_insert_exactor_request(msg_type, false, storage_id, current_path, 0, uid, MS_ITEM_UPDATE);
}
}
- } else {
+ } else if (dir_entry->d_type == DT_DIR) {
new_path = g_strdup(path);
g_ptr_array_add(dir_array, new_path);
ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_DONE, uid);
if (dir) {
- g_dir_close(dir);
+ closedir(dir);
dir = NULL;
}
END_SCAN:
if (dir) {
- g_dir_close(dir);
+ closedir(dir);
dir = NULL;
}