diff options
author | Jochen Keil <jochen.keil@gmail.com> | 2009-03-10 22:09:00 +0100 |
---|---|---|
committer | Jochen Keil <jochen.keil@gmail.com> | 2009-03-10 22:09:51 +0100 |
commit | 756b0022da9d886cc2bffeec530e72f4c0c30f38 (patch) | |
tree | f82bb04f0db89d3b4986c6f5978e19339650d097 | |
parent | cff29f5e8696c49c00d9761b683c9721dc670edb (diff) | |
download | mpd-756b0022da9d886cc2bffeec530e72f4c0c30f38.tar.gz mpd-756b0022da9d886cc2bffeec530e72f4c0c30f38.tar.xz mpd-756b0022da9d886cc2bffeec530e72f4c0c30f38.zip |
Cleaned up update_regular_file() method in update.c
After adding the container_scan() method the update_regular_file() method was quite hard to read.
Now there's update_container_file() which deals with container files.
That way normal container files (i.e. without embedded tracks) are handled by the old code like a regular file.
This will fix some of the odd behaviour observed.
-rw-r--r-- | src/update.c | 171 |
1 files changed, 88 insertions, 83 deletions
diff --git a/src/update.c b/src/update.c index cf0331049..59efdaa30 100644 --- a/src/update.c +++ b/src/update.c @@ -422,109 +422,114 @@ update_archive_file(struct directory *parent, const char *name, } #endif +static bool +update_container_file( struct directory* directory, + const char* name, + const struct stat* st, + const struct decoder_plugin* plugin) +{ + char* vtrack = NULL; + unsigned int tnum = 0; + const char* pathname = map_directory_child_fs(directory, name); + struct directory* contdir = dirvec_find(&directory->children, name); + + // directory exists already + if (contdir != NULL) + { + // modification time not eq. file mod. time + if (contdir->mtime != st->st_mtime) + { + g_message("removing container file: %s", pathname); + + delete_directory(contdir); + contdir = NULL; + + modified = true; + } + else + return true; + } + + // contdir doesn't yet exist + if (contdir == NULL) + { + contdir = make_subdir(directory, name); + contdir->mtime = st->st_mtime; + contdir->device = DEVICE_CONTAINER; + + while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) + { + struct song* song = song_file_new(vtrack, contdir); + if (song == NULL) + return true; + + // shouldn't be necessary but it's there.. + song->mtime = st->st_mtime; + + song->tag = plugin->tag_dup(map_directory_child_fs(contdir, vtrack)); + + songvec_add(&contdir->songs, song); + song = NULL; + + modified = true; + + g_free(vtrack); + } + + if (tnum == 1) + { + delete_directory(contdir); + return false; + } + else + return true; + } + // something went wrong, so return true to return update_regular_file + return true; +} + static void update_regular_file(struct directory *directory, const char *name, const struct stat *st) { - bool no_container = true; const char *suffix = uri_get_suffix(name); const struct decoder_plugin* plugin; #ifdef ENABLE_ARCHIVE const struct archive_plugin *archive; #endif - if (suffix == NULL) return; - else - plugin = decoder_plugin_from_suffix(suffix, false); - if (plugin != NULL) { + if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL) + { + struct song* song = songvec_find(&directory->songs, name); + if (plugin->container_scan != NULL) { - unsigned int tnum = 0; - char* vtrack = NULL; - struct song *song = songvec_find(&directory->songs, name); - const char* pathname = map_directory_child_fs(directory, name); - struct directory* contdir = dirvec_find(&directory->children, name); - - // directory exists already - if (contdir != NULL) + if (update_container_file(directory, name, st, plugin)) { - no_container = false; - - // modification time not eq. file mod. time - if (contdir->mtime != st->st_mtime) - { - g_message("removing directory: %s", pathname); - delete_directory(contdir); - contdir = NULL; - } - } - - // contdir doesn't yet exist - if (contdir == NULL) - { - // is there already a song for this file? - if (song != NULL && (plugin->container_scan(pathname, 1) != NULL)) - { + if (song != NULL) delete_song(directory, song); - song = NULL; - } - - // reset flag if there are no vtracks - no_container = true; - - contdir = make_subdir(directory, name); - contdir->mtime = st->st_mtime; - contdir->device = DEVICE_CONTAINER; - while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) - { - song = songvec_find(&contdir->songs, vtrack); - - if (song == NULL) - { - song = song_file_new(vtrack, contdir); - if (song == NULL) - return; - - // shouldn't be necessary but it's there.. - song->mtime = st->st_mtime; - - song->tag = plugin->tag_dup( - map_directory_child_fs(contdir, vtrack)); - - songvec_add(&contdir->songs, song); - song = NULL; - - modified = true; - } - no_container = false; - g_free(vtrack); - } + return; } } - if (no_container) - { - struct song *song = songvec_find(&directory->songs, name); - - if (song == NULL) { - song = song_file_load(name, directory); - if (song == NULL) - return; - - songvec_add(&directory->songs, song); - modified = true; - g_message("added %s/%s", - directory_get_path(directory), name); - } else if (st->st_mtime != song->mtime) { - g_message("updating %s/%s", - directory_get_path(directory), name); - if (!song_file_update(song)) - delete_song(directory, song); - modified = true; - } + if (song == NULL) { + song = song_file_load(name, directory); + if (song == NULL) + return; + + songvec_add(&directory->songs, song); + modified = true; + g_message("added %s/%s", + directory_get_path(directory), name); + } else if (st->st_mtime != song->mtime) { + g_message("updating %s/%s", + directory_get_path(directory), name); + if (!song_file_update(song)) + delete_song(directory, song); + modified = true; } #ifdef ENABLE_ARCHIVE } else if ((archive = archive_plugin_from_suffix(suffix))) { |