aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-30 13:47:45 +0100
committerMax Kellermann <max@duempel.org>2009-01-30 13:47:45 +0100
commit47bcb5f3c0d024bffa868f687485e6aaad2468b1 (patch)
tree25e17ba4caa4438f5e5a67603afbf1bcec17fdd9
parent6314a8137b8d7900377b01465162bcc17005edd6 (diff)
downloadmpd-47bcb5f3c0d024bffa868f687485e6aaad2468b1.tar.gz
mpd-47bcb5f3c0d024bffa868f687485e6aaad2468b1.tar.xz
mpd-47bcb5f3c0d024bffa868f687485e6aaad2468b1.zip
mapper: remove trailing slashes from music_directory
When the user configures a music_directory with a trailing slash, it may break playlist loading, because MPD expects a double slash. Chop off the trailing slash.
-rw-r--r--NEWS1
-rw-r--r--src/mapper.c16
2 files changed, 16 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index dc2ec9e00..4711e38f6 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ ver 0.14.2 (2009/??/??)
- jack: allocate ring buffers before connecting
- jack: clear "shutdown" flag on reconnect
- jack: reduced sleep time to 1ms
+* mapper: remove trailing slashes from music_directory
ver 0.14.1 (2009/01/17)
diff --git a/src/mapper.c b/src/mapper.c
index b3f86da00..b7ddda209 100644
--- a/src/mapper.c
+++ b/src/mapper.c
@@ -37,6 +37,20 @@ static size_t music_dir_length;
static char *playlist_dir;
static size_t playlist_dir_length;
+/**
+ * Duplicate a string, chop all trailing slashes.
+ */
+static char *
+strdup_chop_slash(const char *path_fs)
+{
+ size_t length = strlen(path_fs);
+
+ while (length > 0 && path_fs[length - 1] == G_DIR_SEPARATOR)
+ --length;
+
+ return g_strndup(path_fs, length);
+}
+
void mapper_init(void)
{
ConfigParam *music_dir_param = parseConfigFilePath(CONF_MUSIC_DIR, 1);
@@ -44,7 +58,7 @@ void mapper_init(void)
int ret;
struct stat st;
- music_dir = g_strdup(music_dir_param->value);
+ music_dir = strdup_chop_slash(music_dir_param->value);
music_dir_length = strlen(music_dir);
ret = stat(music_dir, &st);