*/
#include <malloc.h>
+#include <dirent.h>
#include "media-util.h"
#include "media-server-ipc.h"
static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_path, bool check_exists, bool is_recursive, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- GDir *dir = NULL;
- GError *error = NULL;
- const char *name;
+ DIR *dir = NULL;
+ struct dirent64 *dir_entry = NULL;
GQueue *dir_queue = NULL;
char *current_path = NULL;
- char *path = NULL;
+ char path[MS_FILE_PATH_LEN_MAX] = {0, };
int (*scan_function)(sqlite3 *, const char*, const char*, uid_t) = NULL;
dir_queue = g_queue_new();
continue;
}
- dir = g_dir_open(current_path, 0, &error);
- if (error != NULL) {
- MS_DBG_ERR("g_dir_open fails [%s]", current_path);
+ dir = opendir(current_path);
+ if (!dir) {
+ MS_DBG_SERR("opendir fails [%s]", current_path);
MS_SAFE_FREE(current_path);
- g_error_free(error);
- error = NULL;
continue;
}
if (ms_insert_folder(handle, storage_id, current_path, uid) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("insert folder failed");
- while ((name = g_dir_read_name(dir))) {
+ while ((dir_entry = readdir64(dir))) {
if (__msc_is_power_off()) {
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
break;
}
- if (name[0] == '.')
+ if (dir_entry->d_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;
- }
+ snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, dir_entry->d_name);
+ switch (dir_entry->d_type) {
+ case DT_REG:
/* Check content.scanning.others feature */
if (!ms_check_support_media_type(path)) {
MS_DBG("Unsupported media type");
- MS_SAFE_FREE(path);
continue;
}
if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("failed to update db");
+ break;
+ case DT_LNK:
+ if (!ms_is_valid_symlink(path))
+ break;
- MS_SAFE_FREE(path);
- } else {
+ // fall-through
+ case DT_DIR:
if (is_recursive) {
- g_queue_push_tail(dir_queue, path);
+ g_queue_push_tail(dir_queue, g_strdup(path));
} else {
ret = ms_insert_folder(handle, storage_id, path, uid);
if (ret != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("ms_insert_folder failed");
- MS_SAFE_FREE(path);
}
+ break;
+ default:
+ break;
}
}
MS_SAFE_FREE(current_path);
-
- if (dir)
- g_dir_close(dir);
+ closedir(dir);
+ dir = NULL;
}
g_queue_free_full(dir_queue, g_free);