From 1f0dfb4407344996bbe874525413275b79da12b3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 18 Jan 2009 16:56:07 +0100 Subject: mapper: make the music_directory optional Without a music_directory, MPD is an excellent streaming client. --- src/database.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/database.c') 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) { -- cgit v1.2.3