aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-13 20:54:27 +0200
committerMax Kellermann <max@duempel.org>2011-09-13 20:54:27 +0200
commitb4430839a3413893a027f7a0fc5494af8198e1bb (patch)
treec35a7d8ba0c12b84b4b9af7385a989e15a27698b
parent412cf974a4cf3693cc643ab8ce0c1d733b7e8047 (diff)
downloadmpd-b4430839a3413893a027f7a0fc5494af8198e1bb.tar.gz
mpd-b4430839a3413893a027f7a0fc5494af8198e1bb.tar.xz
mpd-b4430839a3413893a027f7a0fc5494af8198e1bb.zip
database: generate GError when database is disabled
-rw-r--r--src/command.c6
-rw-r--r--src/database.c13
-rw-r--r--src/db_error.h6
3 files changed, 20 insertions, 5 deletions
diff --git a/src/command.c b/src/command.c
index 864b65354..ad13d75bc 100644
--- a/src/command.c
+++ b/src/command.c
@@ -395,6 +395,12 @@ print_error(struct client *client, GError *error)
return print_playlist_result(client, result);
} else if (error->domain == db_quark()) {
switch ((enum db_error)error->code) {
+ case DB_DISABLED:
+ command_error(client, ACK_ERROR_NO_EXIST, "%s",
+ error->message);
+ g_error_free(error);
+ return COMMAND_RETURN_ERROR;
+
case DB_NOT_FOUND:
g_error_free(error);
command_error(client, ACK_ERROR_NO_EXIST, "Not found");
diff --git a/src/database.c b/src/database.c
index d93066389..cb79c1d39 100644
--- a/src/database.c
+++ b/src/database.c
@@ -27,6 +27,7 @@
#include "directory.h"
#include "stats.h"
#include "conf.h"
+#include "glib_compat.h"
#include <glib.h>
@@ -112,12 +113,14 @@ db_walk(const char *uri,
const struct db_visitor *visitor, void *ctx,
GError **error_r)
{
- struct directory *directory;
-
- if (db == NULL)
- return -1;
+ if (db == NULL) {
+ g_set_error_literal(error_r, db_quark(), DB_DISABLED,
+ "No database");
+ return false;
+ }
- if ((directory = db_get_directory(uri)) == NULL) {
+ struct directory *directory = db_get_directory(uri);
+ if (directory == NULL) {
struct song *song;
if (visitor->song != NULL &&
(song = db_get_song(uri)) != NULL)
diff --git a/src/db_error.h b/src/db_error.h
index 35051c40c..d3be582cf 100644
--- a/src/db_error.h
+++ b/src/db_error.h
@@ -23,6 +23,12 @@
#include <glib.h>
enum db_error {
+ /**
+ * The database is disabled, i.e. none is configured in this
+ * MPD instance.
+ */
+ DB_DISABLED,
+
DB_NOT_FOUND,
};