diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2005-03-06 19:00:58 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2005-03-06 19:00:58 +0000 |
commit | 586a21688f20d5f5f39a304ba21562f94c1b1a56 (patch) | |
tree | f80b905ac65b1061825b49f98b9189531fb814ab /src/path.c | |
parent | d60c37f1f9f9ff4db84f9d5432151703308e61fb (diff) | |
download | mpd-586a21688f20d5f5f39a304ba21562f94c1b1a56.tar.gz mpd-586a21688f20d5f5f39a304ba21562f94c1b1a56.tar.xz mpd-586a21688f20d5f5f39a304ba21562f94c1b1a56.zip |
config file change! now 'port' is optional and 'db_file' is required!
also, should have better error reporting when failing to open playlist or
music directory's, or writing the db, etc
git-svn-id: https://svn.musicpd.org/mpd/trunk@3027 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/path.c b/src/path.c index 1d599bda3..c35be7f04 100644 --- a/src/path.c +++ b/src/path.c @@ -28,6 +28,7 @@ #include <sys/stat.h> #include <unistd.h> #include <errno.h> +#include <dirent.h> #ifdef HAVE_LOCALE #ifdef HAVE_LANGINFO_CODESET @@ -110,36 +111,52 @@ char * getFsCharset() { return fsCharset; } -void initPaths(char * playlistDirArg, char * musicDirArg) { +static char * appendSlash(char ** path) { + char * temp = *path; + int len = strlen(temp); + + if(temp[len-1] != '/') { + temp = strdup(*path); + free(*path); + *path = malloc(len+2); + memset(*path, 0, len+2); + memcpy(*path, temp, len); + (*path)[len] = '/'; + } + + return * path; +} + +void initPaths() { + ConfigParam * musicParam = parseConfigFilePath(CONF_MUSIC_DIR, 1); + ConfigParam * playlistParam = parseConfigFilePath(CONF_PLAYLIST_DIR, 1); + ConfigParam * fsCharsetParam = getConfigParam(CONF_FS_CHARSET); + char * charset = NULL; char * originalLocale; - struct stat st; - ConfigParam * param; + DIR * dir; - playlistDir = prependCwdToPathDup(playlistDirArg); - if((stat(playlistDir,&st))<0) { - ERROR("problem stat'ing \"%s\": %s\n", playlistDirArg, strerror(errno)); - exit(EXIT_FAILURE); - } - if(!S_ISDIR(st.st_mode)) { - ERROR("\"%s\" is not a directory: %s\n", playlistDirArg, strerror(errno)); - exit(EXIT_FAILURE); - } + musicDir = appendSlash(&musicParam->value); + playlistDir = appendSlash(&playlistParam->value); - musicDir = prependCwdToPathDup(musicDirArg); - if((stat(musicDir,&st))<0) { - ERROR("problem stat'ing \"%s\"\n",musicDirArg); + if((dir = opendir(playlistDir)) == NULL) { + ERROR("cannot open %s \"%s\" (config line %i): %s\n", + CONF_PLAYLIST_DIR, playlistParam->value, + playlistParam->line, strerror(errno)); exit(EXIT_FAILURE); } - if(!S_ISDIR(st.st_mode)) { - ERROR("\"%s\" is not a directory\n",musicDirArg); + closedir(dir); + + if((dir = opendir(musicDir)) == NULL) { + ERROR("cannot open %s \"%s\" (config line %i): %s\n", + CONF_MUSIC_DIR, musicParam->value, + musicParam->line, strerror(errno)); exit(EXIT_FAILURE); } + closedir(dir); - param = getConfigParam(CONF_FS_CHARSET); - - if(param) { - charset = strdup(param->value); + if(fsCharsetParam) { + charset = strdup(fsCharsetParam->value); } #ifdef HAVE_LOCALE #ifdef HAVE_LANGINFO_CODESET |