static void handle_file_entered_L(const char *ptr) { dmoz_filelist_t tmp; struct stat sb; /* these shenanigans force the file to take another trip... */ if (stat(ptr, &sb) == -1) return; memset(&tmp, 0, sizeof(tmp)); dmoz_add_file(&tmp, str_dup(ptr), str_dup(ptr), &sb, 0); dmoz_free(&tmp, NULL); song_load(ptr); }
bool directory_load(FILE *fp, struct directory *directory, GString *buffer, GError **error) { const char *line; while ((line = read_text_line(fp, buffer)) != NULL && !g_str_has_prefix(line, DIRECTORY_END)) { if (g_str_has_prefix(line, DIRECTORY_DIR)) { struct directory *subdir = directory_load_subdir(fp, directory, line + sizeof(DIRECTORY_DIR) - 1, buffer, error); if (subdir == NULL) return false; dirvec_add(&directory->children, subdir); } else if (g_str_has_prefix(line, SONG_BEGIN)) { const char *name = line + sizeof(SONG_BEGIN) - 1; struct song *song; if (songvec_find(&directory->songs, name) != NULL) { g_set_error(error, directory_quark(), 0, "Duplicate song '%s'", name); return NULL; } song = song_load(fp, directory, name, buffer, error); if (song == NULL) return false; songvec_add(&directory->songs, song); } else { g_set_error(error, directory_quark(), 0, "Malformed line: %s", line); return false; } } return true; }