Commit f16e3728 authored by J. Alexander Treuman's avatar J. Alexander Treuman

Make sure StoredPlaylists always contain UTF-8 paths that are either

relative paths in the DB or URLs. The main functional difference is that playlistmove and playlistdelete will rewrite playlists in the correct encoding and remove invalid lines instead of potentially modifying them. The specific changes are: appendSongToStoredPlaylist: * Don't convert to FS charset * Don't prepend music_directory if saving absolute paths writeStoredPlaylistToPath: * Convert to FS charset * Prepend music_directory if saving absolute paths loadStoredPlaylist: * Make sure each line is either in the DB or a URL loadPlaylist: * Don't bother checking paths, since it's done in loadStoredPlaylist now git-svn-id: https://svn.musicpd.org/mpd/trunk@6266 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent f4d959a0
...@@ -1434,9 +1434,7 @@ int loadPlaylist(int fd, char *utf8file) ...@@ -1434,9 +1434,7 @@ int loadPlaylist(int fd, char *utf8file)
node = sp->list->firstNode; node = sp->list->firstNode;
while (node != NULL) { while (node != NULL) {
char *temp = node->data; char *temp = node->data;
if (!getSongFromDB(temp) && !isRemoteUrl(temp)) { if ((addToPlaylist(STDERR_FILENO, temp, 0)) < 0) {
} else if ((addToPlaylist(STDERR_FILENO, temp, 0)) < 0) {
/* for windows compatibility, convert slashes */ /* for windows compatibility, convert slashes */
char *temp2 = xstrdup(temp); char *temp2 = xstrdup(temp);
char *p = temp2; char *p = temp2;
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "playlist.h" #include "playlist.h"
#include "ack.h" #include "ack.h"
#include "command.h" #include "command.h"
#include "ls.h"
#include "directory.h"
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
...@@ -96,6 +98,11 @@ static ListNode *nodeOfStoredPlaylist(StoredPlaylist *sp, int index) ...@@ -96,6 +98,11 @@ static ListNode *nodeOfStoredPlaylist(StoredPlaylist *sp, int index)
return NULL; return NULL;
} }
static void appendSongToStoredPlaylist(StoredPlaylist *sp, Song *song)
{
insertInListWithoutKey(sp->list, strdup(getSongUrl(song)));
}
StoredPlaylist *newStoredPlaylist(const char *utf8name, int fd, int ignoreExisting) StoredPlaylist *newStoredPlaylist(const char *utf8name, int fd, int ignoreExisting)
{ {
struct stat buf; struct stat buf;
...@@ -138,6 +145,7 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd) ...@@ -138,6 +145,7 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
int parentlen = strlen(parent); int parentlen = strlen(parent);
int tempInt; int tempInt;
int commentCharFound = 0; int commentCharFound = 0;
Song *song;
filename = utf8pathToFsPathInStoredPlaylist(utf8path, fd); filename = utf8pathToFsPathInStoredPlaylist(utf8path, fd);
if (!filename) if (!filename)
...@@ -182,10 +190,22 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd) ...@@ -182,10 +190,22 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
} }
slength = 0; slength = 0;
temp = fsCharsetToUtf8(s); temp = fsCharsetToUtf8(s);
if (!temp) if (temp && !commentCharFound) {
song = getSongFromDB(temp);
if (song) {
appendSongToStoredPlaylist(sp, song);
continue; continue;
if (!commentCharFound) }
insertInListWithoutKey(sp->list, strdup(s));
if (!isValidRemoteUtf8Url(temp))
continue;
song = newSong(temp, SONG_TYPE_URL, NULL);
if (song) {
appendSongToStoredPlaylist(sp, song);
freeJustSong(song);
}
}
} else if (slength == MAXPATHLEN) { } else if (slength == MAXPATHLEN) {
s[slength] = '\0'; s[slength] = '\0';
commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD, commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD,
...@@ -365,8 +385,9 @@ int removeOneSongFromStoredPlaylistByPath(int fd, const char *utf8path, int pos) ...@@ -365,8 +385,9 @@ int removeOneSongFromStoredPlaylistByPath(int fd, const char *utf8path, int pos)
static int writeStoredPlaylistToPath(StoredPlaylist *sp, const char *fspath) static int writeStoredPlaylistToPath(StoredPlaylist *sp, const char *fspath)
{ {
FILE *file;
ListNode *node; ListNode *node;
FILE *file;
char *s;
if (fspath == NULL) if (fspath == NULL)
return -1; return -1;
...@@ -380,7 +401,12 @@ static int writeStoredPlaylistToPath(StoredPlaylist *sp, const char *fspath) ...@@ -380,7 +401,12 @@ static int writeStoredPlaylistToPath(StoredPlaylist *sp, const char *fspath)
node = sp->list->firstNode; node = sp->list->firstNode;
while (node != NULL) { while (node != NULL) {
fprintf(file, "%s\n", (char *)node->data); s = (char *)node->data;
if (isValidRemoteUtf8Url(s) || !playlist_saveAbsolutePaths)
s = utf8ToFsCharset(s);
else
s = rmp2amp(utf8ToFsCharset(s));
fprintf(file, "%s\n", s);
node = node->nextNode; node = node->nextNode;
} }
...@@ -393,22 +419,11 @@ int writeStoredPlaylist(StoredPlaylist *sp) ...@@ -393,22 +419,11 @@ int writeStoredPlaylist(StoredPlaylist *sp)
return writeStoredPlaylistToPath(sp, sp->fspath); return writeStoredPlaylistToPath(sp, sp->fspath);
} }
static void appendSongToStoredPlaylist(StoredPlaylist *sp, Song *song)
{
char *s;
if (playlist_saveAbsolutePaths && song->type == SONG_TYPE_FILE)
s = rmp2amp(utf8ToFsCharset(getSongUrl(song)));
else
s = utf8ToFsCharset(getSongUrl(song));
insertInListWithoutKey(sp->list, strdup(s));
}
int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
{ {
char *filename; char *filename;
FILE *file; FILE *file;
char *s;
filename = utf8pathToFsPathInStoredPlaylist(utf8path, fd); filename = utf8pathToFsPathInStoredPlaylist(utf8path, fd);
if (!filename) if (!filename)
...@@ -422,9 +437,11 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) ...@@ -422,9 +437,11 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
} }
if (playlist_saveAbsolutePaths && song->type == SONG_TYPE_FILE) if (playlist_saveAbsolutePaths && song->type == SONG_TYPE_FILE)
fprintf(file, "%s\n", rmp2amp(utf8ToFsCharset(getSongUrl(song)))); s = rmp2amp(utf8ToFsCharset(getSongUrl(song)));
else else
fprintf(file, "%s\n", utf8ToFsCharset(getSongUrl(song))); s = utf8ToFsCharset(getSongUrl(song));
fprintf(file, "%s\n", s);
while (fclose(file) != 0 && errno == EINTR); while (fclose(file) != 0 && errno == EINTR);
return 0; return 0;
......
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