[vlc-commits] cache: remove CacheDelete() and simplify

Rémi Denis-Courmont git at videolan.org
Wed Oct 26 13:34:50 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 26 14:33:36 2016 +0300| [0874a5656ba5479fa61280d36bcc2d4845b753d7] | committer: Rémi Denis-Courmont

cache: remove CacheDelete() and simplify

CacheSave() already atomically replaces the cache file (or deletes it,
then non-atomically replaces it on retarded systems). There are no
needs to delete it explicitly another time first.

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

 src/modules/bank.c    | 57 +++++++++++++++++++++------------------------------
 src/modules/cache.c   | 13 ------------
 src/modules/modules.h |  1 -
 3 files changed, 23 insertions(+), 48 deletions(-)

diff --git a/src/modules/bank.c b/src/modules/bank.c
index 8e64861..8ac0a3c 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -168,7 +168,7 @@ typedef struct module_bank
     size_t         i_cache;
     module_cache_t *cache;
 
-    int            i_loaded_cache;
+    size_t         i_loaded_cache;
     module_cache_t *loaded_cache;
 } module_bank_t;
 
@@ -307,34 +307,23 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
  * Scans for plug-ins within a file system hierarchy.
  * \param path base directory to browse
  */
-static void AllocatePluginPath (vlc_object_t *p_this, const char *path,
-                                cache_mode_t mode)
+static void AllocatePluginPath(vlc_object_t *obj, const char *path,
+                               cache_mode_t mode)
 {
-    module_bank_t bank;
-    module_cache_t *cache = NULL;
-    size_t count = 0;
-
-    switch( mode )
+    module_bank_t bank =
     {
-        case CACHE_USE:
-            count = CacheLoad(p_this, path, &cache, &modules.caches);
-            break;
-        case CACHE_RESET:
-            CacheDelete( p_this, path );
-            break;
-        case CACHE_IGNORE:
-            msg_Dbg( p_this, "ignoring plugins cache file" );
-    }
-
-    msg_Dbg( p_this, "recursively browsing `%s'", path );
+        .obj = obj,
+        .base = path,
+        .mode = mode,
+    };
+
+    if (mode == CACHE_USE)
+        bank.i_loaded_cache = CacheLoad(bank.obj, bank.base,
+                                        &bank.loaded_cache, &modules.caches);
+    else
+        msg_Dbg(bank.obj, "ignoring plugins cache file");
 
-    bank.obj = p_this;
-    bank.base = path;
-    bank.mode = mode;
-    bank.cache = NULL;
-    bank.i_cache = 0;
-    bank.loaded_cache = cache;
-    bank.i_loaded_cache = count;
+    msg_Dbg(obj, "recursively browsing `%s'", bank.base);
 
     /* Don't go deeper than 5 subdirectories */
     AllocatePluginDir (&bank, 5, path, NULL);
@@ -343,19 +332,19 @@ static void AllocatePluginPath (vlc_object_t *p_this, const char *path,
     {
         case CACHE_USE:
             /* Discard unmatched cache entries */
-            for( size_t i = 0; i < count; i++ )
+            for (size_t i = 0; i < bank.i_loaded_cache; i++)
             {
-                if (cache[i].p_module != NULL)
-                   vlc_module_destroy (cache[i].p_module);
-                free (cache[i].path);
+                if (bank.loaded_cache[i].p_module != NULL)
+                    vlc_module_destroy(bank.loaded_cache[i].p_module);
+                free(bank.loaded_cache[i].path);
             }
-            free( cache );
+            free(bank.loaded_cache);
             for (size_t i = 0; i < bank.i_cache; i++)
-                free (bank.cache[i].path);
-            free (bank.cache);
+                free(bank.cache[i].path);
+            free(bank.cache);
             break;
         case CACHE_RESET:
-            CacheSave (p_this, path, bank.cache, bank.i_cache);
+            CacheSave(obj, path, bank.cache, bank.i_cache);
         case CACHE_IGNORE:
             break;
     }
diff --git a/src/modules/cache.c b/src/modules/cache.c
index 7aebb7f..492b7ed 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -65,19 +65,6 @@
 #define CACHE_STRING "cache "PACKAGE_NAME" "PACKAGE_VERSION
 
 
-void CacheDelete( vlc_object_t *obj, const char *dir )
-{
-    char *path;
-
-    assert( dir != NULL );
-
-    if( asprintf( &path, "%s"DIR_SEP CACHE_NAME, dir ) == -1 )
-        return;
-    msg_Dbg( obj, "removing plugins cache file %s", path );
-    vlc_unlink( path );
-    free( path );
-}
-
 static int vlc_cache_load_immediate(void *out, block_t *in, size_t size)
 {
     if (in->i_buffer < size)
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 10ce0b0..e4f7f2d 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -121,7 +121,6 @@ void module_Unload (module_handle_t);
 
 /* Plugins cache */
 void   CacheMerge (vlc_object_t *, module_t *, module_t *);
-void   CacheDelete(vlc_object_t *, const char *);
 size_t CacheLoad(vlc_object_t *, const char *, module_cache_t **, block_t **);
 
 struct stat;



More information about the vlc-commits mailing list