Commit 9933144d authored by Max Kellermann's avatar Max Kellermann

mapper: make the playlist directory optional

parent c2cc3b49
...@@ -12,6 +12,7 @@ ver 0.15 - (200?/??/??) ...@@ -12,6 +12,7 @@ ver 0.15 - (200?/??/??)
* failure to read the state file is non-fatal * failure to read the state file is non-fatal
* added Icy-Metadata support * added Icy-Metadata support
* --create-db starts the MPD daemon instead of exiting * --create-db starts the MPD daemon instead of exiting
* playlist_directory is optional
ver 0.14.1 (2009/01/17) ver 0.14.1 (2009/01/17)
......
...@@ -32,9 +32,6 @@ configuration file. ...@@ -32,9 +32,6 @@ configuration file.
.B music_directory <directory> .B music_directory <directory>
This specifies the directory where music is located. This specifies the directory where music is located.
.TP .TP
.B playlist_directory <directory>
This specifies the directory where saved playlists are stored.
.TP
.B follow_outside_symlinks <yes or no> .B follow_outside_symlinks <yes or no>
Control if MPD will follow symbolic links pointing outside the music dir. Control if MPD will follow symbolic links pointing outside the music dir.
You must recreate the database after changing this option. You must recreate the database after changing this option.
...@@ -57,6 +54,10 @@ The special value "syslog" makes MPD use the local syslog daemon. ...@@ -57,6 +54,10 @@ The special value "syslog" makes MPD use the local syslog daemon.
.B pid_file <file> .B pid_file <file>
This specifies the file to save mpd's process ID in. This specifies the file to save mpd's process ID in.
.TP .TP
.B playlist_directory <directory>
This specifies the directory where saved playlists are stored.
If you do not configure this, you cannot save playlists.
.TP
.B state_file <file> .B state_file <file>
This specifies if a state file is used and where it is located. The state of This specifies if a state file is used and where it is located. The state of
mpd will be saved to this file when mpd is terminated by a TERM signal or by mpd will be saved to this file when mpd is terminated by a TERM signal or by
......
...@@ -320,6 +320,11 @@ print_playlist_result(struct client *client, ...@@ -320,6 +320,11 @@ print_playlist_result(struct client *client,
command_error(client, ACK_ERROR_PLAYLIST_MAX, command_error(client, ACK_ERROR_PLAYLIST_MAX,
"playlist is at the max size"); "playlist is at the max size");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_DISABLED:
command_error(client, ACK_ERROR_UNKNOWN,
"stored playlist support is disabled");
return COMMAND_RETURN_ERROR;
} }
assert(0); assert(0);
......
...@@ -39,14 +39,29 @@ static char *music_dir; ...@@ -39,14 +39,29 @@ static char *music_dir;
static size_t music_dir_length; static size_t music_dir_length;
static char *playlist_dir; static char *playlist_dir;
static size_t playlist_dir_length;
static void
mapper_set_playlist_dir(const char *path, int line)
{
int ret;
struct stat st;
playlist_dir = g_strdup(path);
ret = stat(playlist_dir, &st);
if (ret < 0)
g_warning("failed to stat playlist directory \"%s\" (config line %i): %s\n",
playlist_dir, line, g_strerror(errno));
else if (!S_ISDIR(st.st_mode))
g_warning("playlist directory is not a directory: \"%s\" (config line %i)\n",
playlist_dir, line);
}
void mapper_init(void) void mapper_init(void)
{ {
struct config_param *music_dir_param = struct config_param *music_dir_param =
parseConfigFilePath(CONF_MUSIC_DIR, false); parseConfigFilePath(CONF_MUSIC_DIR, false);
struct config_param *playlist_dir_param = struct config_param *param;
parseConfigFilePath(CONF_PLAYLIST_DIR, 1);
int ret; int ret;
struct stat st; struct stat st;
...@@ -73,17 +88,9 @@ void mapper_init(void) ...@@ -73,17 +88,9 @@ void mapper_init(void)
g_warning("music directory is not a directory: \"%s\" (config line %i)\n", g_warning("music directory is not a directory: \"%s\" (config line %i)\n",
music_dir_param->value, music_dir_param->line); music_dir_param->value, music_dir_param->line);
playlist_dir = g_strdup(playlist_dir_param->value); param = parseConfigFilePath(CONF_PLAYLIST_DIR, false);
playlist_dir_length = strlen(playlist_dir); if (param != NULL)
mapper_set_playlist_dir(param->value, param->line);
ret = stat(playlist_dir, &st);
if (ret < 0)
g_warning("failed to stat playlist directory \"%s\" (config line %i): %s\n",
playlist_dir_param->value, playlist_dir_param->line,
strerror(errno));
else if (!S_ISDIR(st.st_mode))
g_warning("playlist directory is not a directory: \"%s\" (config line %i)\n",
playlist_dir_param->value, playlist_dir_param->line);
} }
void mapper_finish(void) void mapper_finish(void)
...@@ -183,6 +190,9 @@ map_spl_utf8_to_fs(const char *name) ...@@ -183,6 +190,9 @@ map_spl_utf8_to_fs(const char *name)
char *filename = g_strconcat(name, "." PLAYLIST_FILE_SUFFIX, NULL); char *filename = g_strconcat(name, "." PLAYLIST_FILE_SUFFIX, NULL);
char *path; char *path;
if (playlist_dir == NULL)
return NULL;
path = g_build_filename(playlist_dir, filename, NULL); path = g_build_filename(playlist_dir, filename, NULL);
g_free(filename); g_free(filename);
......
...@@ -1216,6 +1216,9 @@ enum playlist_result savePlaylist(const char *utf8file) ...@@ -1216,6 +1216,9 @@ enum playlist_result savePlaylist(const char *utf8file)
return PLAYLIST_RESULT_BAD_NAME; return PLAYLIST_RESULT_BAD_NAME;
path = map_spl_utf8_to_fs(utf8file); path = map_spl_utf8_to_fs(utf8file);
if (path == NULL)
return PLAYLIST_RESULT_DISABLED;
if (g_file_test(path, G_FILE_TEST_EXISTS)) { if (g_file_test(path, G_FILE_TEST_EXISTS)) {
g_free(path); g_free(path);
return PLAYLIST_RESULT_LIST_EXISTS; return PLAYLIST_RESULT_LIST_EXISTS;
......
...@@ -38,7 +38,8 @@ enum playlist_result { ...@@ -38,7 +38,8 @@ enum playlist_result {
PLAYLIST_RESULT_BAD_NAME, PLAYLIST_RESULT_BAD_NAME,
PLAYLIST_RESULT_BAD_RANGE, PLAYLIST_RESULT_BAD_RANGE,
PLAYLIST_RESULT_NOT_PLAYING, PLAYLIST_RESULT_NOT_PLAYING,
PLAYLIST_RESULT_TOO_LARGE PLAYLIST_RESULT_TOO_LARGE,
PLAYLIST_RESULT_DISABLED,
}; };
typedef struct _Playlist { typedef struct _Playlist {
......
...@@ -80,6 +80,9 @@ spl_list(void) ...@@ -80,6 +80,9 @@ spl_list(void)
GPtrArray *list; GPtrArray *list;
struct stored_playlist_info *playlist; struct stored_playlist_info *playlist;
if (parent_path_fs == NULL)
return NULL;
dir = opendir(parent_path_fs); dir = opendir(parent_path_fs);
if (dir == NULL) if (dir == NULL)
return NULL; return NULL;
...@@ -118,6 +121,8 @@ spl_save(GPtrArray *list, const char *utf8path) ...@@ -118,6 +121,8 @@ spl_save(GPtrArray *list, const char *utf8path)
assert(utf8path != NULL); assert(utf8path != NULL);
path_fs = map_spl_utf8_to_fs(utf8path); path_fs = map_spl_utf8_to_fs(utf8path);
if (path_fs == NULL)
return PLAYLIST_RESULT_DISABLED;
while (!(file = fopen(path_fs, "w")) && errno == EINTR); while (!(file = fopen(path_fs, "w")) && errno == EINTR);
g_free(path_fs); g_free(path_fs);
...@@ -145,6 +150,8 @@ spl_load(const char *utf8path) ...@@ -145,6 +150,8 @@ spl_load(const char *utf8path)
return NULL; return NULL;
path_fs = map_spl_utf8_to_fs(utf8path); path_fs = map_spl_utf8_to_fs(utf8path);
if (path_fs == NULL)
return NULL;
while (!(file = fopen(path_fs, "r")) && errno == EINTR); while (!(file = fopen(path_fs, "r")) && errno == EINTR);
g_free(path_fs); g_free(path_fs);
...@@ -264,6 +271,8 @@ spl_clear(const char *utf8path) ...@@ -264,6 +271,8 @@ spl_clear(const char *utf8path)
return PLAYLIST_RESULT_BAD_NAME; return PLAYLIST_RESULT_BAD_NAME;
path_fs = map_spl_utf8_to_fs(utf8path); path_fs = map_spl_utf8_to_fs(utf8path);
if (path_fs == NULL)
return PLAYLIST_RESULT_DISABLED;
while (!(file = fopen(path_fs, "w")) && errno == EINTR); while (!(file = fopen(path_fs, "w")) && errno == EINTR);
g_free(path_fs); g_free(path_fs);
...@@ -283,6 +292,9 @@ spl_delete(const char *name_utf8) ...@@ -283,6 +292,9 @@ spl_delete(const char *name_utf8)
int ret; int ret;
path_fs = map_spl_utf8_to_fs(name_utf8); path_fs = map_spl_utf8_to_fs(name_utf8);
if (path_fs == NULL)
return PLAYLIST_RESULT_DISABLED;
ret = unlink(path_fs); ret = unlink(path_fs);
g_free(path_fs); g_free(path_fs);
if (ret < 0) if (ret < 0)
...@@ -330,6 +342,8 @@ spl_append_song(const char *utf8path, struct song *song) ...@@ -330,6 +342,8 @@ spl_append_song(const char *utf8path, struct song *song)
return PLAYLIST_RESULT_BAD_NAME; return PLAYLIST_RESULT_BAD_NAME;
path_fs = map_spl_utf8_to_fs(utf8path); path_fs = map_spl_utf8_to_fs(utf8path);
if (path_fs == NULL)
return PLAYLIST_RESULT_DISABLED;
while (!(file = fopen(path_fs, "a")) && errno == EINTR); while (!(file = fopen(path_fs, "a")) && errno == EINTR);
g_free(path_fs); g_free(path_fs);
...@@ -410,7 +424,10 @@ spl_rename(const char *utf8from, const char *utf8to) ...@@ -410,7 +424,10 @@ spl_rename(const char *utf8from, const char *utf8to)
from_path_fs = map_spl_utf8_to_fs(utf8from); from_path_fs = map_spl_utf8_to_fs(utf8from);
to_path_fs = map_spl_utf8_to_fs(utf8to); to_path_fs = map_spl_utf8_to_fs(utf8to);
ret = spl_rename_internal(from_path_fs, to_path_fs); if (from_path_fs != NULL && to_path_fs != NULL)
ret = spl_rename_internal(from_path_fs, to_path_fs);
else
ret = PLAYLIST_RESULT_DISABLED;
g_free(from_path_fs); g_free(from_path_fs);
g_free(to_path_fs); g_free(to_path_fs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment