diff options
Diffstat (limited to 'src/mapper.c')
-rw-r--r-- | src/mapper.c | 46 |
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) |