core/collection: Clean up path scanning code
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
8e5cc543c3
commit
49457751c9
|
@ -13,62 +13,66 @@ extern "C" {
|
|||
static struct queue library_q;
|
||||
static struct file c_file;
|
||||
|
||||
struct scan_info {
|
||||
struct library *library;
|
||||
std :: string path;
|
||||
struct scan_data {
|
||||
struct library *sd_lib;
|
||||
gchar *sd_path;
|
||||
};
|
||||
|
||||
static void scan_path(void *);
|
||||
static void __scan_dir(void *);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Scanning functions are here
|
||||
*/
|
||||
static void tag_track(struct library *library, const std::string &filepath)
|
||||
static void __scan_dir_later(struct library *library, const gchar *dir)
|
||||
{
|
||||
struct track *track = track_add(library, filepath.c_str());
|
||||
if (track)
|
||||
queue_add(&library_q, track);
|
||||
struct scan_data *data = new struct scan_data;
|
||||
|
||||
data->sd_lib = library;
|
||||
data->sd_path = g_strdup(dir);
|
||||
|
||||
/* data is freed by __scan_dir() */
|
||||
idle_schedule(__scan_dir, data);
|
||||
}
|
||||
|
||||
static void process_path(struct library *library, const std :: string &dir,
|
||||
const std :: string &name)
|
||||
static void __scan_path(struct scan_data *scan, const gchar *name)
|
||||
{
|
||||
struct scan_info *scan = new struct scan_info;
|
||||
scan->library = library;
|
||||
scan->path = dir + "/" + name;
|
||||
gchar *path = g_strdup_printf("%s/%s", scan->sd_path, name);
|
||||
struct track *track;
|
||||
|
||||
if (g_file_test(scan->path.c_str(), G_FILE_TEST_IS_DIR) == true)
|
||||
idle_schedule (scan_path, scan);
|
||||
if (g_file_test(path, G_FILE_TEST_IS_DIR))
|
||||
__scan_dir_later(scan->sd_lib, path);
|
||||
else {
|
||||
tag_track(library, scan->path);
|
||||
delete scan;
|
||||
track = track_add(scan->sd_lib, path);
|
||||
if (track)
|
||||
queue_add(&library_q, track);
|
||||
}
|
||||
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
static void scan_path(void *data)
|
||||
static void __scan_dir(void *data)
|
||||
{
|
||||
GDir *dir;
|
||||
struct scan_data *scan = (struct scan_data *)data;
|
||||
GDir *dir = g_dir_open(scan->sd_path, 0, NULL);
|
||||
const char *name;
|
||||
struct scan_info *scan = (struct scan_info *)data;
|
||||
|
||||
dir = g_dir_open(scan->path.c_str(), 0, NULL);
|
||||
if (dir == NULL)
|
||||
return;
|
||||
goto out;
|
||||
|
||||
name = g_dir_read_name(dir);
|
||||
while (name != NULL) {
|
||||
process_path(scan->library, scan->path, name);
|
||||
__scan_path(scan, name);
|
||||
name = g_dir_read_name(dir);
|
||||
}
|
||||
|
||||
g_dir_close(dir);
|
||||
track_db_commit();
|
||||
|
||||
out:
|
||||
/* Allocated by __scan_dir_later() */
|
||||
g_free(scan->sd_path);
|
||||
delete scan;
|
||||
}
|
||||
|
||||
static void validate_library(void *data)
|
||||
static void __validate_library(void *data)
|
||||
{
|
||||
struct library *library = (struct library *)data;
|
||||
struct db_entry *dbe, *next;
|
||||
|
@ -180,16 +184,11 @@ void collection_remove(struct library *library)
|
|||
|
||||
void collection_update(struct library *library)
|
||||
{
|
||||
struct scan_info *scan;
|
||||
|
||||
if (!library)
|
||||
return;
|
||||
|
||||
scan = new struct scan_info;
|
||||
scan->library = library;
|
||||
scan->path = library->li_path;
|
||||
idle_schedule(validate_library, library);
|
||||
idle_schedule(scan_path, scan);
|
||||
idle_schedule(__validate_library, library);
|
||||
__scan_dir_later(library, library->li_path);
|
||||
}
|
||||
|
||||
void collection_update_all()
|
||||
|
|
Loading…
Reference in New Issue