summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Boulton <richard@tartarus.org>2001-01-07 07:01:37 +0000
committerRichard Boulton <richard@tartarus.org>2001-01-07 07:01:37 +0000
commit81aa7d16b0a9d0100fef92985b91e6e365df171c (patch)
tree35d24fcf2d34ce3a156c524ba4df3ac22523ffdd
parent7b865ef7fd9b0fcab99cfed85a8d64e47cc35f9e (diff)
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.
-rw-r--r--gst/gstplugin.c62
-rw-r--r--tools/gstreamer-register.c7
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);