diff --git a/core/library.cpp b/core/library.cpp index 1ae19d2a..7f83bb0e 100644 --- a/core/library.cpp +++ b/core/library.cpp @@ -63,8 +63,8 @@ static void scan_path(void *data) name = g_dir_read_name(dir); } - track_db_commit(); g_dir_close(dir); + track_db_commit(); delete scan; } @@ -180,14 +180,16 @@ void collection_remove(struct library *library) void collection_update(struct library *library) { - struct scan_info *scan = new struct scan_info; - scan->library = library; + struct scan_info *scan; - if (library) { - scan->path = library->li_path; - idle_schedule(validate_library, library); - idle_schedule(scan_path, 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); } void collection_update_all() diff --git a/tests/core/library.cpp b/tests/core/library.cpp index 04bf734f..831be689 100644 --- a/tests/core/library.cpp +++ b/tests/core/library.cpp @@ -64,6 +64,11 @@ static void test_update() struct queue *q = collection_get_queue(); struct library *lib = library_get(0); + collection_update(NULL); + test_equal(track_db_get()->db_size, 48); + test_equal(lib->li_size, 48); + test_equal(queue_size(q), 48); + g_rename("tests/Music/Hyrule Symphony/", "tests/Music/symphony/"); collection_update(lib);