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.
This commit is contained in:
parent
cff29f5e86
commit
756b0022da
169
src/update.c
169
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;
|
||||
|
||||
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;
|
||||
}
|
||||
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))) {
|
||||
|
Loading…
Reference in New Issue
Block a user