diff options
Diffstat (limited to '')
-rw-r--r-- | src/directory.c | 34 | ||||
-rw-r--r-- | src/directory.h | 22 | ||||
-rw-r--r-- | src/directory_save.c | 4 | ||||
-rw-r--r-- | src/update_walk.c | 18 |
4 files changed, 64 insertions, 14 deletions
diff --git a/src/directory.c b/src/directory.c index 0dbc23847..3700579af 100644 --- a/src/directory.c +++ b/src/directory.c @@ -177,11 +177,41 @@ directory_lookup_directory(struct directory *directory, const char *uri) return found; } +void +directory_add_song(struct directory *directory, struct song *song) +{ + assert(directory != NULL); + assert(song != NULL); + assert(song->parent == directory); + + songvec_add(&directory->songs, song); +} + +void +directory_remove_song(struct directory *directory, struct song *song) +{ + assert(directory != NULL); + assert(song != NULL); + assert(song->parent == directory); + + songvec_delete(&directory->songs, song); +} + +struct song * +directory_get_song(const struct directory *directory, const char *name_utf8) +{ + assert(directory != NULL); + assert(name_utf8 != NULL); + + struct song *song = songvec_find(&directory->songs, name_utf8); + assert(song == NULL || song->parent == directory); + return song; +} + struct song * directory_lookup_song(struct directory *directory, const char *uri) { char *duplicated, *base; - struct song *song; assert(directory != NULL); assert(uri != NULL); @@ -199,7 +229,7 @@ directory_lookup_song(struct directory *directory, const char *uri) } else base = duplicated; - song = songvec_find(&directory->songs, base); + struct song *song = directory_get_song(directory, base); assert(song == NULL || song->parent == directory); g_free(duplicated); diff --git a/src/directory.h b/src/directory.h index b6e199555..b866295ae 100644 --- a/src/directory.h +++ b/src/directory.h @@ -181,6 +181,28 @@ struct directory * directory_lookup_directory(struct directory *directory, const char *uri); /** + * Add a song object to this directory. Its "parent" attribute must + * be set already. + */ +void +directory_add_song(struct directory *directory, struct song *song); + +/** + * Remove a song object from this directory (which effectively + * invalidates the song object, because the "parent" attribute becomes + * stale), but does not free it. + */ +void +directory_remove_song(struct directory *directory, struct song *song); + +/** + * Look up a song in this directory by its name. + */ +G_GNUC_PURE +struct song * +directory_get_song(const struct directory *directory, const char *name_utf8); + +/** * Looks up a song by its relative URI. * * @param directory the parent (or grandparent, ...) directory diff --git a/src/directory_save.c b/src/directory_save.c index 087c99fe4..087fab4c7 100644 --- a/src/directory_save.c +++ b/src/directory_save.c @@ -146,7 +146,7 @@ directory_load(FILE *fp, struct directory *directory, const char *name = line + sizeof(SONG_BEGIN) - 1; struct song *song; - if (songvec_find(&directory->songs, name) != NULL) { + if (directory_get_song(directory, name) != NULL) { g_set_error(error, directory_quark(), 0, "Duplicate song '%s'", name); return NULL; @@ -157,7 +157,7 @@ directory_load(FILE *fp, struct directory *directory, if (song == NULL) return false; - songvec_add(&directory->songs, song); + directory_add_song(directory, song); } else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) { /* duplicate the name, because playlist_metadata_load() will overwrite the diff --git a/src/update_walk.c b/src/update_walk.c index 1c0bb30b6..728e5bb04 100644 --- a/src/update_walk.c +++ b/src/update_walk.c @@ -93,7 +93,7 @@ static void delete_song(struct directory *dir, struct song *del) { /* first, prevent traversers in main task from getting this */ - songvec_delete(&dir->songs, del); + directory_remove_song(dir, del); /* now take it out of the playlist (in the main_task) */ update_remove_song(del); @@ -144,13 +144,13 @@ static void delete_name_in(struct directory *parent, const char *name) { struct directory *directory = directory_get_child(parent, name); - struct song *song = songvec_find(&parent->songs, name); if (directory != NULL) { delete_directory(directory); modified = true; } + struct song *song = directory_get_song(parent, name); if (song != NULL) { delete_song(parent, song); modified = true; @@ -357,7 +357,6 @@ static void update_archive_tree(struct directory *directory, char *name) { struct directory *subdir; - struct song *song; char *tmp; tmp = strchr(name, '/'); @@ -377,11 +376,11 @@ update_archive_tree(struct directory *directory, char *name) return; } //add file - song = songvec_find(&directory->songs, name); + struct song *song = directory_get_song(directory, name); if (song == NULL) { song = song_file_load(name, directory); if (song != NULL) { - songvec_add(&directory->songs, song); + directory_add_song(directory, song); modified = true; g_message("added %s/%s", directory_get_path(directory), name); @@ -499,7 +498,7 @@ update_container_file( struct directory* directory, song->tag = plugin->tag_dup(child_path_fs); g_free(child_path_fs); - songvec_add(&contdir->songs, song); + directory_add_song(contdir, song); modified = true; @@ -559,7 +558,7 @@ update_regular_file(struct directory *directory, if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL) { - struct song* song = songvec_find(&directory->songs, name); + struct song *song = directory_get_song(directory, name); if (!directory_child_access(directory, name, R_OK)) { g_warning("no read permissions on %s/%s", @@ -592,7 +591,7 @@ update_regular_file(struct directory *directory, return; } - songvec_add(&directory->songs, song); + directory_add_song(directory, song); modified = true; g_message("added %s/%s", directory_get_path(directory), name); @@ -800,7 +799,6 @@ directory_make_child_checked(struct directory *parent, const char *name_utf8) { struct directory *directory; struct stat st; - struct song *conflicting; directory = directory_get_child(parent, name_utf8); if (directory != NULL) @@ -812,7 +810,7 @@ directory_make_child_checked(struct directory *parent, const char *name_utf8) /* if we're adding directory paths, make sure to delete filenames with potentially the same name */ - conflicting = songvec_find(&parent->songs, name_utf8); + struct song *conflicting = directory_get_song(parent, name_utf8); if (conflicting) delete_song(parent, conflicting); |