mapper: apply filesystem_charset to playlists
This fixes an inconsistency in the stored playlist subsystem: when obtaining the list of playlists (listplaylist, listplaylistinfo), the file names in the playlist directory are converted to UTF-8 (according to filesystem_charset), but when saving or loading playlists, the filesystem_charset setting was ignored.
This commit is contained in:
parent
cd69fee0a4
commit
f4b707b4ca
1
NEWS
1
NEWS
|
@ -4,6 +4,7 @@ ver 0.15.7 (2009/??/??)
|
||||||
* decoders:
|
* decoders:
|
||||||
- ffmpeg: don't try to force stereo
|
- ffmpeg: don't try to force stereo
|
||||||
* mapper: fix memory leak when playlist_directory is not set
|
* mapper: fix memory leak when playlist_directory is not set
|
||||||
|
* mapper: apply filesystem_charset to playlists
|
||||||
* command: verify playlist name in the "rm" command
|
* command: verify playlist name in the "rm" command
|
||||||
|
|
||||||
|
|
||||||
|
|
13
src/mapper.c
13
src/mapper.c
|
@ -221,14 +221,19 @@ map_spl_path(void)
|
||||||
char *
|
char *
|
||||||
map_spl_utf8_to_fs(const char *name)
|
map_spl_utf8_to_fs(const char *name)
|
||||||
{
|
{
|
||||||
char *filename, *path;
|
char *filename_utf8, *filename_fs, *path;
|
||||||
|
|
||||||
if (playlist_dir == NULL)
|
if (playlist_dir == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
filename = g_strconcat(name, PLAYLIST_FILE_SUFFIX, NULL);
|
filename_utf8 = g_strconcat(name, PLAYLIST_FILE_SUFFIX, NULL);
|
||||||
path = g_build_filename(playlist_dir, filename, NULL);
|
filename_fs = utf8_to_fs_charset(filename_utf8);
|
||||||
g_free(filename);
|
g_free(filename_utf8);
|
||||||
|
if (filename_fs == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
path = g_build_filename(playlist_dir, filename_fs, NULL);
|
||||||
|
g_free(filename_fs);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,8 @@ map_spl_path(void);
|
||||||
* Maps a playlist name (without the ".m3u" suffix) to a file system
|
* Maps a playlist name (without the ".m3u" suffix) to a file system
|
||||||
* path. The return value is allocated on the heap and must be freed
|
* path. The return value is allocated on the heap and must be freed
|
||||||
* with g_free().
|
* with g_free().
|
||||||
|
*
|
||||||
|
* @return the path in file system encoding, or NULL if mapping failed
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
map_spl_utf8_to_fs(const char *name);
|
map_spl_utf8_to_fs(const char *name);
|
||||||
|
|
|
@ -71,12 +71,15 @@ spl_save_queue(const char *name_utf8, const struct queue *queue)
|
||||||
char *path_fs;
|
char *path_fs;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
|
if (map_spl_path() == NULL)
|
||||||
|
return PLAYLIST_RESULT_DISABLED;
|
||||||
|
|
||||||
if (!spl_valid_name(name_utf8))
|
if (!spl_valid_name(name_utf8))
|
||||||
return PLAYLIST_RESULT_BAD_NAME;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
path_fs = map_spl_utf8_to_fs(name_utf8);
|
path_fs = map_spl_utf8_to_fs(name_utf8);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return PLAYLIST_RESULT_DISABLED;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
if (g_file_test(path_fs, G_FILE_TEST_EXISTS)) {
|
if (g_file_test(path_fs, G_FILE_TEST_EXISTS)) {
|
||||||
g_free(path_fs);
|
g_free(path_fs);
|
||||||
|
|
|
@ -152,9 +152,12 @@ spl_save(GPtrArray *list, const char *utf8path)
|
||||||
|
|
||||||
assert(utf8path != NULL);
|
assert(utf8path != NULL);
|
||||||
|
|
||||||
|
if (map_spl_path() == NULL)
|
||||||
|
return PLAYLIST_RESULT_DISABLED;
|
||||||
|
|
||||||
path_fs = map_spl_utf8_to_fs(utf8path);
|
path_fs = map_spl_utf8_to_fs(utf8path);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return PLAYLIST_RESULT_DISABLED;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
while (!(file = fopen(path_fs, "w")) && errno == EINTR);
|
while (!(file = fopen(path_fs, "w")) && errno == EINTR);
|
||||||
g_free(path_fs);
|
g_free(path_fs);
|
||||||
|
@ -178,7 +181,7 @@ spl_load(const char *utf8path)
|
||||||
char buffer[MPD_PATH_MAX];
|
char buffer[MPD_PATH_MAX];
|
||||||
char *path_fs;
|
char *path_fs;
|
||||||
|
|
||||||
if (!spl_valid_name(utf8path))
|
if (!spl_valid_name(utf8path) || map_spl_path() == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
path_fs = map_spl_utf8_to_fs(utf8path);
|
path_fs = map_spl_utf8_to_fs(utf8path);
|
||||||
|
@ -299,12 +302,15 @@ spl_clear(const char *utf8path)
|
||||||
char *path_fs;
|
char *path_fs;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
|
if (map_spl_path() == NULL)
|
||||||
|
return PLAYLIST_RESULT_DISABLED;
|
||||||
|
|
||||||
if (!spl_valid_name(utf8path))
|
if (!spl_valid_name(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)
|
if (path_fs == NULL)
|
||||||
return PLAYLIST_RESULT_DISABLED;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
while (!(file = fopen(path_fs, "w")) && errno == EINTR);
|
while (!(file = fopen(path_fs, "w")) && errno == EINTR);
|
||||||
g_free(path_fs);
|
g_free(path_fs);
|
||||||
|
@ -323,12 +329,15 @@ spl_delete(const char *name_utf8)
|
||||||
char *path_fs;
|
char *path_fs;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (map_spl_path() == NULL)
|
||||||
|
return PLAYLIST_RESULT_DISABLED;
|
||||||
|
|
||||||
if (!spl_valid_name(name_utf8))
|
if (!spl_valid_name(name_utf8))
|
||||||
return PLAYLIST_RESULT_BAD_NAME;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
path_fs = map_spl_utf8_to_fs(name_utf8);
|
path_fs = map_spl_utf8_to_fs(name_utf8);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return PLAYLIST_RESULT_DISABLED;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
ret = unlink(path_fs);
|
ret = unlink(path_fs);
|
||||||
g_free(path_fs);
|
g_free(path_fs);
|
||||||
|
@ -373,12 +382,15 @@ spl_append_song(const char *utf8path, struct song *song)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *path_fs;
|
char *path_fs;
|
||||||
|
|
||||||
|
if (map_spl_path() == NULL)
|
||||||
|
return PLAYLIST_RESULT_DISABLED;
|
||||||
|
|
||||||
if (!spl_valid_name(utf8path))
|
if (!spl_valid_name(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)
|
if (path_fs == NULL)
|
||||||
return PLAYLIST_RESULT_DISABLED;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
while (!(file = fopen(path_fs, "a")) && errno == EINTR);
|
while (!(file = fopen(path_fs, "a")) && errno == EINTR);
|
||||||
g_free(path_fs);
|
g_free(path_fs);
|
||||||
|
@ -448,6 +460,9 @@ spl_rename(const char *utf8from, const char *utf8to)
|
||||||
char *from_path_fs, *to_path_fs;
|
char *from_path_fs, *to_path_fs;
|
||||||
static enum playlist_result ret;
|
static enum playlist_result ret;
|
||||||
|
|
||||||
|
if (map_spl_path() == NULL)
|
||||||
|
return PLAYLIST_RESULT_DISABLED;
|
||||||
|
|
||||||
if (!spl_valid_name(utf8from) || !spl_valid_name(utf8to))
|
if (!spl_valid_name(utf8from) || !spl_valid_name(utf8to))
|
||||||
return PLAYLIST_RESULT_BAD_NAME;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
|
@ -457,7 +472,7 @@ spl_rename(const char *utf8from, const char *utf8to)
|
||||||
if (from_path_fs != NULL && to_path_fs != NULL)
|
if (from_path_fs != NULL && to_path_fs != NULL)
|
||||||
ret = spl_rename_internal(from_path_fs, to_path_fs);
|
ret = spl_rename_internal(from_path_fs, to_path_fs);
|
||||||
else
|
else
|
||||||
ret = PLAYLIST_RESULT_DISABLED;
|
ret = PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
g_free(from_path_fs);
|
g_free(from_path_fs);
|
||||||
g_free(to_path_fs);
|
g_free(to_path_fs);
|
||||||
|
|
Loading…
Reference in New Issue