diff options
author | Max Kellermann <max@duempel.org> | 2012-06-13 21:04:43 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-06-13 21:22:00 +0200 |
commit | 20029e7ce8967c2c92d2bd05864835d82fa526da (patch) | |
tree | da5653727dcb69e6ca5f2dc4402a4fa0f8f85862 /src | |
parent | fcb7950811d9e714f66f90613699b6682ff2f74d (diff) | |
download | mpd-20029e7ce8967c2c92d2bd05864835d82fa526da.tar.gz mpd-20029e7ce8967c2c92d2bd05864835d82fa526da.tar.xz mpd-20029e7ce8967c2c92d2bd05864835d82fa526da.zip |
update_walk: move code to make_directory_if_modified()
Diffstat (limited to 'src')
-rw-r--r-- | src/update_walk.c | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/src/update_walk.c b/src/update_walk.c index 974ebe8dd..e07203782 100644 --- a/src/update_walk.c +++ b/src/update_walk.c @@ -308,39 +308,57 @@ update_archive_file(struct directory *parent, const char *name, } #endif +/** + * Create the specified directory object if it does not exist already + * or if the #stat object indicates that it has been modified since + * the last update. Returns NULL when it exists already and is + * unmodified. + * + * The caller must lock the database. + */ +static struct directory * +make_directory_if_modified(struct directory *parent, const char *name, + const struct stat *st) +{ + struct directory *directory = directory_get_child(parent, name); + + // directory exists already + if (directory != NULL) { + if (directory->mtime == st->st_mtime && !walk_discard) { + /* not modified */ + db_unlock(); + return NULL; + } + + delete_directory(directory); + modified = true; + } + + directory = directory_make_child(parent, name); + directory->mtime = st->st_mtime; + return directory; +} + static bool update_container_file(struct directory *directory, const char *name, const struct stat *st, const struct decoder_plugin *plugin) { - char *pathname = map_directory_child_fs(directory, name); - db_lock(); - struct directory *contdir = directory_get_child(directory, name); - - // directory exists already - if (contdir != NULL) { - // modification time not eq. file mod. time - if (contdir->mtime != st->st_mtime || walk_discard) { - g_message("removing container file: %s", pathname); - - delete_directory(contdir); - contdir = NULL; - - modified = true; - } else { - db_unlock(); - g_free(pathname); - return true; - } + struct directory *contdir = + make_directory_if_modified(directory, name, st); + if (contdir == NULL) { + /* not modified */ + db_unlock(); + return true; } - contdir = directory_make_child(directory, name); - contdir->mtime = st->st_mtime; contdir->device = DEVICE_CONTAINER; db_unlock(); + char *const pathname = map_directory_child_fs(directory, name); + char *vtrack; unsigned int tnum = 0; while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) { |