Commit 20029e7c authored by Max Kellermann's avatar Max Kellermann

update_walk: move code to make_directory_if_modified()

parent fcb79508
...@@ -308,39 +308,57 @@ update_archive_file(struct directory *parent, const char *name, ...@@ -308,39 +308,57 @@ update_archive_file(struct directory *parent, const char *name,
} }
#endif #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 static bool
update_container_file(struct directory *directory, update_container_file(struct directory *directory,
const char *name, const char *name,
const struct stat *st, const struct stat *st,
const struct decoder_plugin *plugin) const struct decoder_plugin *plugin)
{ {
char *pathname = map_directory_child_fs(directory, name);
db_lock(); db_lock();
struct directory *contdir = directory_get_child(directory, name); struct directory *contdir =
make_directory_if_modified(directory, name, st);
// directory exists already if (contdir == NULL) {
if (contdir != NULL) { /* not modified */
// modification time not eq. file mod. time db_unlock();
if (contdir->mtime != st->st_mtime || walk_discard) { return true;
g_message("removing container file: %s", pathname);
delete_directory(contdir);
contdir = NULL;
modified = true;
} else {
db_unlock();
g_free(pathname);
return true;
}
} }
contdir = directory_make_child(directory, name);
contdir->mtime = st->st_mtime;
contdir->device = DEVICE_CONTAINER; contdir->device = DEVICE_CONTAINER;
db_unlock(); db_unlock();
char *const pathname = map_directory_child_fs(directory, name);
char *vtrack; char *vtrack;
unsigned int tnum = 0; unsigned int tnum = 0;
while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) { while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment