From cf15629aeae7b2f750388c6823f43cd5918676a4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Nov 2011 09:35:50 +0100 Subject: mapper: move code to check_directory() --- src/mapper.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/mapper.c') diff --git a/src/mapper.c b/src/mapper.c index 108de9531..426b2980f 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -51,25 +51,28 @@ strdup_chop_slash(const char *path_fs) return g_strndup(path_fs, length); } +static void +check_directory(const char *path) +{ + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + g_warning("Not a directory: %s", path); +} + 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) -- cgit v1.2.3 From cead5e5bd75ed2d71f3834adcb02e3d99082df7f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Nov 2011 09:37:05 +0100 Subject: mapper: fix the bogus "not a directory" error message Use stat() instead of g_file_test() to detect other types of errors, such as "permission denied". --- src/mapper.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/mapper.c') diff --git a/src/mapper.c b/src/mapper.c index 426b2980f..30d932f95 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -31,6 +31,9 @@ #include #include +#include +#include +#include static char *music_dir; static size_t music_dir_length; @@ -54,8 +57,17 @@ strdup_chop_slash(const char *path_fs) static void check_directory(const char *path) { - if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + 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; + } } static void -- cgit v1.2.3 From 718e180423aeb84fc513858415a201905630580c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Nov 2011 09:44:36 +0100 Subject: mapper: check "x" permission on music directory This is a common support case, and hopefully, the new error message will allow the user to understand the error without requiring support. --- src/mapper.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/mapper.c') diff --git a/src/mapper.c b/src/mapper.c index 30d932f95..41ed6550b 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -68,6 +68,14 @@ check_directory(const char *path) 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 } static void -- cgit v1.2.3 From 6f365c30eb33c40193defb827b03a8fd293bfc23 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Nov 2011 09:56:03 +0100 Subject: mapper: check "r" permission on music directory Yet another common support case. --- src/mapper.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/mapper.c') diff --git a/src/mapper.c b/src/mapper.c index 41ed6550b..3cee41eb3 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -34,6 +34,7 @@ #include #include #include +#include static char *music_dir; static size_t music_dir_length; @@ -76,6 +77,12 @@ check_directory(const char *path) 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 -- cgit v1.2.3