diff options
-rw-r--r-- | src/decoder_thread.c | 39 | ||||
-rw-r--r-- | src/mapper.c | 23 | ||||
-rw-r--r-- | src/mapper.h | 9 | ||||
-rw-r--r-- | src/playlist_save.c | 6 | ||||
-rw-r--r-- | src/song.c | 16 | ||||
-rw-r--r-- | src/update.c | 32 |
6 files changed, 72 insertions, 53 deletions
diff --git a/src/decoder_thread.c b/src/decoder_thread.c index de82cb6d3..35d6e3206 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -74,27 +74,14 @@ decoder_file_decode(const struct decoder_plugin *plugin, return dc.state != DECODE_STATE_START; } -static void decoder_run(void) +static void decoder_run_song(const struct song *song, const char *uri) { - struct song *song = dc.next_song; - char buffer[MPD_PATH_MAX]; - const char *uri; struct decoder decoder; int ret; bool close_instream = true; struct input_stream input_stream; const struct decoder_plugin *plugin; - if (song_is_file(song)) - uri = map_song_fs(song, buffer); - else - uri = song_get_url(song, buffer); - if (uri == NULL) { - dc.state = DECODE_STATE_ERROR; - return; - } - - dc.current_song = dc.next_song; /* NEED LOCK */ if (!input_stream_open(&input_stream, uri)) { dc.state = DECODE_STATE_ERROR; return; @@ -202,6 +189,30 @@ static void decoder_run(void) dc.state = ret ? DECODE_STATE_STOP : DECODE_STATE_ERROR; } +static void decoder_run(void) +{ + struct song *song = dc.next_song; + char *uri; + + if (song_is_file(song)) + uri = map_song_fs(song); + else { + char buffer[MPD_PATH_MAX]; + + uri = g_strdup(song_get_url(song, buffer)); + } + + if (uri == NULL) { + dc.state = DECODE_STATE_ERROR; + return; + } + + dc.current_song = dc.next_song; /* NEED LOCK */ + decoder_run_song(song, uri); + g_free(uri); + +} + static gpointer decoder_task(G_GNUC_UNUSED gpointer arg) { do { diff --git a/src/mapper.c b/src/mapper.c index 6b0a7a449..bd19af615 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -108,11 +108,11 @@ map_directory_fs(const struct directory *directory) return map_uri_fs(dirname); } -const char * -map_directory_child_fs(const struct directory *directory, const char *name, - char *buffer) +char * +map_directory_child_fs(const struct directory *directory, const char *name) { - char *parent_fs; + char buffer[MPD_PATH_MAX]; + char *parent_fs, *path; /* check for invalid or unauthorized base names */ if (*name == 0 || strchr(name, '/') != NULL || @@ -124,21 +124,22 @@ map_directory_child_fs(const struct directory *directory, const char *name, return NULL; name = utf8_to_fs_charset(buffer, name); - pfx_dir(buffer, name, strlen(name), - parent_fs, strlen(parent_fs)); + path = g_build_filename(parent_fs, name, NULL); g_free(parent_fs); - return buffer; + return path; } -const char * -map_song_fs(const struct song *song, char *buffer) +char * +map_song_fs(const struct song *song) { + char buffer[MPD_PATH_MAX]; + assert(song_is_file(song)); if (song_in_database(song)) - return map_directory_child_fs(song->parent, song->url, buffer); + return map_directory_child_fs(song->parent, song->url); else - return utf8_to_fs_charset(buffer, song->url); + return g_strdup(utf8_to_fs_charset(buffer, song->url)); } const char * diff --git a/src/mapper.h b/src/mapper.h index ee8d34dab..74af0d133 100644 --- a/src/mapper.h +++ b/src/mapper.h @@ -59,9 +59,8 @@ map_directory_fs(const struct directory *directory); * @param a buffer which is MPD_PATH_MAX bytes long * @return the path in file system encoding, or NULL if mapping failed */ -const char * -map_directory_child_fs(const struct directory *directory, const char *name, - char *buffer); +char * +map_directory_child_fs(const struct directory *directory, const char *name); /** * Determines the file system path of a song. This must not be a @@ -71,8 +70,8 @@ map_directory_child_fs(const struct directory *directory, const char *name, * @param a buffer which is MPD_PATH_MAX bytes long * @return the path in file system encoding, or NULL if mapping failed */ -const char * -map_song_fs(const struct song *song, char *buffer); +char * +map_song_fs(const struct song *song); /** * Maps a file system path (relative to the music directory or diff --git a/src/playlist_save.c b/src/playlist_save.c index b6bc99369..4c9d0b2f4 100644 --- a/src/playlist_save.c +++ b/src/playlist_save.c @@ -32,9 +32,11 @@ playlist_print_song(FILE *file, const struct song *song) char tmp1[MPD_PATH_MAX], tmp2[MPD_PATH_MAX]; if (playlist_saveAbsolutePaths && song_in_database(song)) { - const char *path = map_song_fs(song, tmp1); - if (path != NULL) + char *path = map_song_fs(song); + if (path != NULL) { fprintf(file, "%s\n", path); + g_free(path); + } } else { song_get_url(song, tmp1); utf8_to_fs_charset(tmp2, tmp1); diff --git a/src/song.c b/src/song.c index b7a8d2f8a..4d93073a9 100644 --- a/src/song.c +++ b/src/song.c @@ -104,15 +104,14 @@ song_free(struct song *song) bool song_file_update(struct song *song) { - char buffer[MPD_PATH_MAX]; - const char *path_fs; + char *path_fs; const struct decoder_plugin *plugin; unsigned int next = 0; struct stat st; assert(song_is_file(song)); - path_fs = map_song_fs(song, buffer); + path_fs = map_song_fs(song); if (path_fs == NULL) return false; @@ -121,8 +120,10 @@ song_file_update(struct song *song) song->tag = NULL; } - if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) + if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) { + g_free(path_fs); return false; + } song->mtime = st.st_mtime; @@ -130,19 +131,19 @@ song_file_update(struct song *song) (plugin = hasMusicSuffix(path_fs, next++))) song->tag = plugin->tag_dup(path_fs); + g_free(path_fs); return song->tag != NULL; } bool song_file_update_inarchive(struct song *song) { - char buffer[MPD_PATH_MAX]; - const char *path_fs; + char *path_fs; const struct decoder_plugin *plugin; assert(song_is_file(song)); - path_fs = map_song_fs(song, buffer); + path_fs = map_song_fs(song); if (path_fs == NULL) return false; @@ -154,6 +155,7 @@ song_file_update_inarchive(struct song *song) //because we dont support tag reading throught //input streams plugin = hasMusicSuffix(path_fs, 0); + g_free(path_fs); if (plugin) { song->tag = tag_new(); //tag_add_item(tag, TAG_ITEM_TITLE, f->title); diff --git a/src/update.c b/src/update.c index 08360edd2..79db6ee43 100644 --- a/src/update.c +++ b/src/update.c @@ -163,7 +163,6 @@ delete_name_in(struct directory *parent, const char *name) } struct delete_data { - char *tmp; struct directory *dir; }; @@ -172,19 +171,21 @@ static int delete_song_if_removed(struct song *song, void *_data) { struct delete_data *data = _data; - const char *path; + char *path; struct stat st; - if ((path = map_song_fs(song, data->tmp)) == NULL || - stat(data->tmp, &st) < 0 || !S_ISREG(st.st_mode)) { + if ((path = map_song_fs(song)) == NULL || + stat(path, &st) < 0 || !S_ISREG(st.st_mode)) { delete_song(data->dir, song); modified = true; } + + g_free(path); return 0; } static void -removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory) +removeDeletedFromDirectory(struct directory *directory) { int i; struct dirvec *dv = &directory->children; @@ -208,7 +209,6 @@ removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory) } data.dir = directory; - data.tmp = path_max_tmp; songvec_for_each(&directory->songs, delete_song_if_removed, &data); } @@ -230,14 +230,16 @@ static int stat_directory_child(const struct directory *parent, const char *name, struct stat *st) { - char buffer[MPD_PATH_MAX]; - const char *path_fs; + char *path_fs; + int ret; - path_fs = map_directory_child_fs(parent, name, buffer); + path_fs = map_directory_child_fs(parent, name); if (path_fs == NULL) return -1; - return stat(path_fs, st); + ret = stat(path_fs, st); + g_free(path_fs); + return ret; } static int @@ -424,14 +426,16 @@ static bool skip_symlink(const struct directory *directory, const char *utf8_name) { char buffer[MPD_PATH_MAX]; + char *path_fs; const char *p; ssize_t ret; - p = map_directory_child_fs(directory, utf8_name, buffer); - if (p == NULL) + path_fs = map_directory_child_fs(directory, utf8_name); + if (path_fs == NULL) return true; - ret = readlink(p, buffer, sizeof(buffer)); + ret = readlink(path_fs, buffer, sizeof(buffer)); + g_free(path_fs); if (ret < 0) /* don't skip if this is not a symlink */ return errno != EINVAL; @@ -493,7 +497,7 @@ updateDirectory(struct directory *directory, const struct stat *st) if (!dir) return false; - removeDeletedFromDirectory(path_max_tmp, directory); + removeDeletedFromDirectory(directory); while ((ent = readdir(dir))) { char *utf8; |