aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/update.c171
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))) {