diff options
author | Max Kellermann <max@duempel.org> | 2009-01-18 16:56:07 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-18 16:56:07 +0100 |
commit | 1f0dfb4407344996bbe874525413275b79da12b3 (patch) | |
tree | 6da8c04bf1e3c6143927d3a69eecb3532f88939f /src/database.c | |
parent | 9933144de7389b12b2a75cfb4320baecefa952af (diff) | |
download | mpd-1f0dfb4407344996bbe874525413275b79da12b3.tar.gz mpd-1f0dfb4407344996bbe874525413275b79da12b3.tar.xz mpd-1f0dfb4407344996bbe874525413275b79da12b3.zip |
mapper: make the music_directory optional
Without a music_directory, MPD is an excellent streaming client.
Diffstat (limited to 'src/database.c')
-rw-r--r-- | src/database.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/database.c b/src/database.c index 44909aced..6beb84f61 100644 --- a/src/database.c +++ b/src/database.c @@ -49,13 +49,17 @@ db_init(const char *path) { database_path = g_strdup(path); - music_root = directory_new("", NULL); + if (path != NULL) + music_root = directory_new("", NULL); } void db_finish(void) { - directory_free(music_root); + assert((database_path == NULL) == (music_root == NULL)); + + if (music_root != NULL) + directory_free(music_root); g_free(database_path); } @@ -63,6 +67,8 @@ db_finish(void) void db_clear(void) { + assert(music_root != NULL); + directory_free(music_root); music_root = directory_new("", NULL); } @@ -78,6 +84,9 @@ db_get_root(void) struct directory * db_get_directory(const char *name) { + if (music_root == NULL) + return NULL; + if (name == NULL) return music_root; @@ -89,14 +98,20 @@ db_get_song(const char *file) { struct song *song = NULL; struct directory *directory; - char *dir = NULL; - char *duplicated = g_strdup(file); - char *shortname = strrchr(duplicated, '/'); + char *duplicated, *shortname, *dir; + + assert(file != NULL); g_debug("get song: %s", file); + if (music_root == NULL) + return NULL; + + duplicated = g_strdup(file); + shortname = strrchr(duplicated, '/'); if (!shortname) { shortname = duplicated; + dir = NULL; } else { *shortname = '\0'; ++shortname; @@ -121,6 +136,9 @@ db_walk(const char *name, { struct directory *directory; + if (music_root == NULL) + return -1; + if ((directory = db_get_directory(name)) == NULL) { struct song *song; if ((song = db_get_song(name)) && forEachSong) { |