diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-11 23:39:50 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-11 23:39:50 -0700 |
commit | 0df62a2c3cb7af88347d40a17cc336b5d1740f62 (patch) | |
tree | 25040833144c3e24f6b4702d9b745cd068b5371a /src/song.c | |
parent | 3456e2de5bf90207d8149a842bb12c3f9bdd218f (diff) | |
parent | 6e2b0ca9edaed200f250ef487701ad161aa4a168 (diff) | |
download | mpd-0df62a2c3cb7af88347d40a17cc336b5d1740f62.tar.gz mpd-0df62a2c3cb7af88347d40a17cc336b5d1740f62.tar.xz mpd-0df62a2c3cb7af88347d40a17cc336b5d1740f62.zip |
Merge branch 'mk/directory'
* mk/directory: (59 commits)
directory: don't use identical struct and variable names
update: replaced update_return with global "modified" flag
update: make the variable "progress" static
update: don't print debug message when song was not modified
update: fix memory leak in directory_update_init()
update: make the job id unsigned
update: job ID must be positive
update: check progress!=IDLE in reap_update_task()
update: fixed stack corruption due to pthread_join() call
updated: always call removeDeletedFromDirectory()
update: eliminated addSubDirectoryToDirectory()
update: make the "song" variable more local
update: do the recursive directory check only once
update: copy stat to new directory
update: avoid duplicate stat() calls
update: rewrote updatePath() using updateInDirectory()
update: don't export updateDirectory()
update: pass const pointer to addSubDirectoryToDirectory()
update: never pass root path to updatePath()
update: merged addDirectoryPathToDB() into addParentPathToDB()
...
Conflicts:
src/song.c
Diffstat (limited to '')
-rw-r--r-- | src/song.c | 139 |
1 files changed, 66 insertions, 73 deletions
diff --git a/src/song.c b/src/song.c index ddc3bc4bd..aa6641020 100644 --- a/src/song.c +++ b/src/song.c @@ -29,74 +29,69 @@ #include "os_compat.h" -static Song * song_alloc(const char *url, Directory *parent) +static struct mpd_song * song_alloc(const char *url, struct directory *parent) { size_t urllen; - Song *song; + struct mpd_song *song; assert(url); urllen = strlen(url); assert(urllen); - song = xmalloc(sizeof(Song) + urllen); + song = xmalloc(sizeof(*song) - sizeof(song->url) + urllen + 1); song->tag = NULL; memcpy(song->url, url, urllen + 1); - song->parentDir = parent; + song->parent = parent; return song; } -Song *newSong(const char *url, Directory * parentDir) +struct mpd_song * song_remote_new(const char *url) { - Song *song; - assert(*url); + return song_alloc(url, NULL); +} - if (strchr(url, '\n')) { - DEBUG("newSong: '%s' is not a valid uri\n", url); - return NULL; - } +struct mpd_song * song_file_new(const char *path, struct directory *parent) +{ + assert(parent != NULL); - song = song_alloc(url, parentDir); + return song_alloc(path, parent); +} - if (song_is_file(song)) { - InputPlugin *plugin; - unsigned int next = 0; - char path_max_tmp[MPD_PATH_MAX]; - char abs_path[MPD_PATH_MAX]; +struct mpd_song * song_file_load(const char *path, struct directory *parent) +{ + struct mpd_song *song; - utf8_to_fs_charset(abs_path, get_song_url(path_max_tmp, song)); - rmp2amp_r(abs_path, abs_path); + if (strchr(path, '\n')) { + DEBUG("song_file_load: '%s' is not a valid uri\n", path); + return NULL; + } - while (!song->tag && (plugin = isMusic(abs_path, - &(song->mtime), - next++))) { - song->tag = plugin->tagDupFunc(abs_path); - } - if (!song->tag || song->tag->time < 0) { - freeJustSong(song); - song = NULL; - } + song = song_file_new(path, parent); + if (!song_file_update(song)) { + song_free(song); + return NULL; } return song; } -void freeJustSong(Song * song) +void song_free(struct mpd_song * song) { if (song->tag) tag_free(song->tag); free(song); } -ssize_t song_print_url(Song *song, int fd) +ssize_t song_print_url(struct mpd_song *song, int fd) { - if (song->parentDir && song->parentDir->path) + if (song->parent && song->parent->path) return fdprintf(fd, "%s%s/%s\n", SONG_FILE, - getDirectoryPath(song->parentDir), song->url); + directory_get_path(song->parent), song->url); return fdprintf(fd, "%s%s\n", SONG_FILE, song->url); } -ssize_t song_print_info(Song *song, int fd) +ssize_t song_print_info(struct mpd_song *song, int fd) { ssize_t ret = song_print_url(song, fd); @@ -108,19 +103,19 @@ ssize_t song_print_info(Song *song, int fd) return ret; } -int song_print_info_x(Song * song, void *data) +int song_print_info_x(struct mpd_song * song, void *data) { return song_print_info(song, (int)(size_t)data); } -int song_print_url_x(Song * song, void *data) +int song_print_url_x(struct mpd_song * song, void *data) { return song_print_url(song, (int)(size_t)data); } -static void insertSongIntoList(struct songvec *sv, Song *newsong) +static void insertSongIntoList(struct songvec *sv, struct mpd_song *newsong) { - Song *existing = songvec_find(sv, newsong->url); + struct mpd_song *existing = songvec_find(sv, newsong->url); if (!existing) { songvec_add(sv, newsong); @@ -141,10 +136,10 @@ static void insertSongIntoList(struct songvec *sv, Song *newsong) if (old_tag) tag_free(old_tag); } - /* prevent tag_free in freeJustSong */ + /* prevent tag_free in song_free */ newsong->tag = NULL; } - freeJustSong(newsong); + song_free(newsong); } } @@ -162,19 +157,19 @@ static int matchesAnMpdTagItemKey(char *buffer, int *itemType) return 0; } -void readSongInfoIntoList(FILE * fp, Directory * parentDir) +void readSongInfoIntoList(FILE * fp, struct directory * parent) { char buffer[MPD_PATH_MAX + 1024]; int bufferSize = MPD_PATH_MAX + 1024; - Song *song = NULL; - struct songvec *sv = &parentDir->songs; + struct mpd_song *song = NULL; + struct songvec *sv = &parent->songs; int itemType; while (myFgets(buffer, bufferSize, fp) && 0 != strcmp(SONG_END, buffer)) { if (!prefixcmp(buffer, SONG_KEY)) { if (song) insertSongIntoList(sv, song); - song = song_alloc(buffer + strlen(SONG_KEY), parentDir); + song = song_file_new(buffer + strlen(SONG_KEY), parent); } else if (*buffer == 0) { /* ignore empty lines (starting with '\0') */ } else if (song == NULL) { @@ -209,49 +204,47 @@ void readSongInfoIntoList(FILE * fp, Directory * parentDir) insertSongIntoList(sv, song); } -int updateSongInfo(Song * song) +int song_file_update(struct mpd_song * song) { - if (song_is_file(song)) { - InputPlugin *plugin; - unsigned int next = 0; - char path_max_tmp[MPD_PATH_MAX]; - char abs_path[MPD_PATH_MAX]; - struct mpd_tag *old_tag = song->tag; - struct mpd_tag *new_tag = NULL; - - utf8_to_fs_charset(abs_path, get_song_url(path_max_tmp, song)); - rmp2amp_r(abs_path, abs_path); - - while ((plugin = isMusic(abs_path, &song->mtime, next++))) { - if ((new_tag = plugin->tagDupFunc(abs_path))) - break; - } - if (new_tag && tag_equal(new_tag, old_tag)) { - tag_free(new_tag); - } else { - song->tag = new_tag; - if (old_tag) - tag_free(old_tag); - } - if (!song->tag || song->tag->time < 0) - return -1; + InputPlugin *plugin; + unsigned int next = 0; + char path_max_tmp[MPD_PATH_MAX]; + char abs_path[MPD_PATH_MAX]; + struct mpd_tag *old_tag = song->tag; + struct mpd_tag *new_tag = NULL; + + assert(song_is_file(song)); + + utf8_to_fs_charset(abs_path, song_get_url(song, path_max_tmp)); + rmp2amp_r(abs_path, abs_path); + + while ((plugin = isMusic(abs_path, &song->mtime, next++))) { + if ((new_tag = plugin->tagDupFunc(abs_path))) + break; + } + if (new_tag && tag_equal(new_tag, old_tag)) { + tag_free(new_tag); + } else { + song->tag = new_tag; + if (old_tag) + tag_free(old_tag); } - return 0; + return (song->tag && song->tag->time >= 0); } -char *get_song_url(char *path_max_tmp, Song *song) +char *song_get_url(struct mpd_song *song, char *path_max_tmp) { if (!song) return NULL; assert(*song->url); - if (!song->parentDir || !song->parentDir->path) + if (!song->parent || !song->parent->path) strcpy(path_max_tmp, song->url); else pfx_dir(path_max_tmp, song->url, strlen(song->url), - getDirectoryPath(song->parentDir), - strlen(getDirectoryPath(song->parentDir))); + directory_get_path(song->parent), + strlen(directory_get_path(song->parent))); return path_max_tmp; } |