[vlc-commits] modules: drop stale cache entries

Rémi Denis-Courmont git at videolan.org
Thu Oct 27 20:42:42 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 27 21:38:58 2016 +0300| [8efecdc7c53ec844ce62600ed558620bf787fa75] | committer: Rémi Denis-Courmont

modules: drop stale cache entries

There can only be one plugin file with a given path, so if the name
matches but the size or time does not, we know the entry is stale and
useless.

Also print an error if it happens.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8efecdc7c53ec844ce62600ed558620bf787fa75
---

 src/modules/bank.c    | 14 +++++++++++++-
 src/modules/cache.c   | 10 ++--------
 src/modules/modules.h |  5 +----
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/modules/bank.c b/src/modules/bank.c
index 1065c1e..945c050 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -172,7 +172,19 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
 
     /* Check our plugins cache first then load plugin if needed */
     if (bank->mode == CACHE_USE)
-        plugin = vlc_cache_lookup(&bank->cache, relpath, st);
+    {
+        plugin = vlc_cache_lookup(&bank->cache, relpath);
+
+        if (plugin->mtime != (int64_t)st->st_mtime
+         || plugin->size != (uint64_t)st->st_size)
+        {
+            msg_Err(bank->obj, "stale plugins cache: modified %s",
+                    plugin->abspath);
+            vlc_plugin_destroy(plugin);
+            plugin = NULL;
+        }
+    }
+
     if (plugin == NULL)
     {
         plugin = module_InitDynamic(bank->obj, abspath, true);
diff --git a/src/modules/cache.c b/src/modules/cache.c
index 088a3b5..9e0180e 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -726,19 +726,13 @@ out:
 /**
  * Looks up a plugin file in a table of cached plugins.
  */
-vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **cache,
-                               const char *path, const struct stat *st)
+vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **cache, const char *path)
 {
     vlc_plugin_t **pp = cache, *plugin;
 
     while ((plugin = *pp) != NULL)
     {
-        /* TODO: Preemptively delete plugins with matching name and different
-         * stats. This will save time in following look-ups. */
-        if (plugin->path != NULL
-         && !strcmp(plugin->path, path)
-         && plugin->mtime == (int64_t)st->st_mtime
-         && plugin->size == (uint64_t)st->st_size)
+        if (plugin->path != NULL && !strcmp(plugin->path, path))
         {
             *pp = plugin->next;
             plugin->next = NULL;
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 2742e4f..65f720d 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -128,10 +128,7 @@ void module_Unload (module_handle_t);
 
 /* Plugins cache */
 vlc_plugin_t *vlc_cache_load(vlc_object_t *, const char *, block_t **);
-
-struct stat;
-vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **,
-                               const char *relpath, const struct stat *st);
+vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **, const char *relpath);
 
 int CacheAdd(vlc_plugin_t ***, size_t *, vlc_plugin_t *);
 void CacheSave(vlc_object_t *, const char *, vlc_plugin_t *const *, size_t);



More information about the vlc-commits mailing list