From 81aa7d16b0a9d0100fef92985b91e6e365df171c Mon Sep 17 00:00:00 2001 From: Richard Boulton Date: Sun, 7 Jan 2001 07:01:37 +0000 Subject: [PATCH] Check plugin repository up-to-dateness by scanning through all directories on path, and checking that they and all th... Original commit message from CVS: Check plugin repository up-to-dateness by scanning through all directories on path, and checking that they and all their files are older than the repository. Give warning message if not. --- gst/gstplugin.c | 62 +++++++++++++++++++++++++++++++++++++- tools/gstreamer-register.c | 7 +++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/gst/gstplugin.c b/gst/gstplugin.c index 2dfef45675..ea960959c4 100644 --- a/gst/gstplugin.c +++ b/gst/gstplugin.c @@ -47,6 +47,8 @@ gint _gst_libraries_seqno; /* whether or not to spew library load issues */ gboolean _gst_plugin_spew = FALSE; +static gboolean plugin_times_older_than(time_t regtime); +static time_t get_time(const char * path); void _gst_plugin_initialize (void) @@ -81,7 +83,8 @@ _gst_plugin_initialize (void) doc = xmlParseFile (GST_CONFIG_DIR"/reg.xml"); - if (!doc || strcmp (doc->root->name, "GST-PluginRegistry")) { + if (!doc || strcmp (doc->root->name, "GST-PluginRegistry") || + !plugin_times_older_than(get_time(GST_CONFIG_DIR"/reg.xml"))) { g_warning ("gstplugin: registry needs rebuild\n"); gst_plugin_load_all (); return; @@ -89,6 +92,63 @@ _gst_plugin_initialize (void) gst_plugin_load_thyself (doc->root); } +static time_t +get_time(const char * path) +{ + struct stat statbuf; + if (stat(path, &statbuf)) return 0; + if (statbuf.st_mtime > statbuf.st_ctime) return statbuf.st_mtime; + return statbuf.st_ctime; +} + +static gboolean +plugin_times_older_than_recurse(gchar *path, time_t regtime) +{ + DIR *dir; + struct dirent *dirent; + + time_t pathtime = get_time(path); + + if (pathtime > regtime) { + GST_INFO (GST_CAT_PLUGIN_LOADING, + "time for %s was %ld; more recent than registry time of %ld\n", + path, (long)pathtime, (long)regtime); + return FALSE; + } + + dir = opendir(path); + if (dir) { + while ((dirent = readdir(dir))) { + /* don't want to recurse in place or backwards */ + if (strcmp(dirent->d_name,".") && strcmp(dirent->d_name,"..")) { + if (!plugin_times_older_than_recurse( + g_strjoin("/",path,dirent->d_name,NULL), regtime)) + return FALSE; + } + } + closedir(dir); + } + return TRUE; +} + +static gboolean +plugin_times_older_than(time_t regtime) +{ + // return true iff regtime is more recent than the times of all the files + // in the plugin dirs. + GList *path; + path = _gst_plugin_paths; + while (path != NULL) { + GST_DEBUG (GST_CAT_PLUGIN_LOADING, + "comparing plugin times from %s with %ld\n", + (gchar *)path->data, (long) regtime); + if(!plugin_times_older_than_recurse(path->data, regtime)) + return FALSE; + path = g_list_next(path); + } + return TRUE; +} + static gboolean gst_plugin_load_recurse (gchar *directory, gchar *name) { diff --git a/tools/gstreamer-register.c b/tools/gstreamer-register.c index fad9c5478d..2000ffaaab 100644 --- a/tools/gstreamer-register.c +++ b/tools/gstreamer-register.c @@ -101,14 +101,17 @@ int main(int argc,char *argv[]) { xmlDocPtr doc; + // Init gst + _gst_plugin_spew = TRUE; + gst_init(&argc,&argv); + + // Check args if (argc != 1) usage(argv[0]); // Check that directory for config exists check_dir(GLOBAL_REGISTRY_DIR); // Read the plugins - _gst_plugin_spew = TRUE; - gst_init(&argc,&argv); doc = xmlNewDoc("1.0"); doc->root = xmlNewDocNode(doc, NULL, "GST-PluginRegistry", NULL); gst_plugin_save_thyself(doc->root);