aboutsummaryrefslogtreecommitdiffstats
path: root/src/mapper.c
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:50:24 +0100
commite3d4fa6946140d91c02a8ae53e56ab8d056f172c (patch)
tree6401b6f662741436dc0b3b83fd69e4c55ce17861 /src/mapper.c
parentefb04532df68a52c7e8911d210b271298bc45d1f (diff)
downloadmpd-e3d4fa6946140d91c02a8ae53e56ab8d056f172c.tar.gz
mpd-e3d4fa6946140d91c02a8ae53e56ab8d056f172c.tar.xz
mpd-e3d4fa6946140d91c02a8ae53e56ab8d056f172c.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.
Diffstat (limited to '')
-rw-r--r--src/mapper.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mapper.c b/src/mapper.c
index 28471e60e..1eecbf283 100644
--- a/src/mapper.c
+++ b/src/mapper.c
@@ -40,13 +40,27 @@ static size_t music_dir_length;
static char *playlist_dir;
+/**
+ * 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);
+}
+
static void
mapper_set_music_dir(const char *path)
{
int ret;
struct stat st;
- music_dir = g_strdup(path);
+ music_dir = strdup_chop_slash(path);
music_dir_length = strlen(music_dir);
ret = stat(music_dir, &st);