aboutsummaryrefslogtreecommitdiffstats
path: root/src/mapper.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-11-28 11:56:01 +0100
committerMax Kellermann <max@duempel.org>2011-11-28 11:56:01 +0100
commit4f093d5b979c3547c8dd8045dde5d91e8cc93461 (patch)
tree94b1c12cfce14c90f26852e948ba419a8a7ba7eb /src/mapper.c
parent37420c342bf9582a0de32d46f78716e913119400 (diff)
parente1b032cbad5db7698104a93c2235fb7da1f8b580 (diff)
downloadmpd-4f093d5b979c3547c8dd8045dde5d91e8cc93461.tar.gz
mpd-4f093d5b979c3547c8dd8045dde5d91e8cc93461.tar.xz
mpd-4f093d5b979c3547c8dd8045dde5d91e8cc93461.zip
Merge branch 'v0.16.x'
Conflicts: Makefile.am NEWS configure.ac src/encoder/flac_encoder.c src/log.c src/pcm_buffer.c
Diffstat (limited to 'src/mapper.c')
-rw-r--r--src/mapper.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/mapper.c b/src/mapper.c
index 091db50b0..4aa4e0b14 100644
--- a/src/mapper.c
+++ b/src/mapper.c
@@ -31,6 +31,10 @@
#include <assert.h>
#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
static char *music_dir;
static size_t music_dir_length;
@@ -52,24 +56,50 @@ strdup_chop_slash(const char *path_fs)
}
static void
+check_directory(const char *path)
+{
+ struct stat st;
+ if (stat(path, &st) < 0) {
+ g_warning("Failed to stat directory \"%s\": %s",
+ path, g_strerror(errno));
+ return;
+ }
+
+ if (!S_ISDIR(st.st_mode)) {
+ g_warning("Not a directory: %s", path);
+ return;
+ }
+
+#ifndef WIN32
+ char *x = g_build_filename(path, ".", NULL);
+ if (stat(x, &st) < 0 && errno == EACCES)
+ g_warning("No permission to traverse (\"execute\") directory: %s",
+ path);
+ g_free(x);
+#endif
+
+ DIR *dir = opendir(path);
+ if (dir == NULL && errno == EACCES)
+ g_warning("No permission to read directory: %s", path);
+ else
+ closedir(dir);
+}
+
+static void
mapper_set_music_dir(const char *path)
{
+ check_directory(path);
+
music_dir = strdup_chop_slash(path);
music_dir_length = strlen(music_dir);
-
- if (!g_file_test(music_dir, G_FILE_TEST_IS_DIR))
- g_warning("music directory is not a directory: \"%s\"",
- music_dir);
}
static void
mapper_set_playlist_dir(const char *path)
{
- playlist_dir = g_strdup(path);
+ check_directory(path);
- if (!g_file_test(playlist_dir, G_FILE_TEST_IS_DIR))
- g_warning("playlist directory is not a directory: \"%s\"",
- playlist_dir);
+ playlist_dir = g_strdup(path);
}
void mapper_init(const char *_music_dir, const char *_playlist_dir)