]> git.sesse.net Git - vlc/commitdiff
Load/delete plugins cache from plugins directory
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 30 Jan 2010 21:32:54 +0000 (23:32 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 30 Jan 2010 21:32:54 +0000 (23:32 +0200)
Also refactor. Deletion and loading are now distinct functions.

src/libvlc.c
src/modules/cache.c
src/modules/modules.c
src/modules/modules.h

index 7f7bed61f152a22a8a23dc4d4a0891c06c59dd8a..3ffade517337f008846e7322915b92e415d95a06 100644 (file)
@@ -344,9 +344,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         i_ret = VLC_EEXITSUCCESS;
     }
 
-    /* Check for plugins cache options */
-    bool b_cache_delete = var_InheritBool( p_libvlc, "reset-plugins-cache" );
-
     /* Check for daemon mode */
 #ifndef WIN32
     if( var_InheritBool( p_libvlc, "daemon" ) )
@@ -446,7 +443,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      * list of configuration options exported by each module and loads their
      * default values.
      */
-    module_LoadPlugins( p_libvlc, b_cache_delete );
+    module_LoadPlugins( p_libvlc );
     if( p_libvlc->b_die )
     {
         b_exit = true;
index a872adc33509c4c24efcf446c681d1d4413503d4..d8efe76b09b7efda0d94196befc98ac9b3837da7 100644 (file)
@@ -68,6 +68,20 @@ static int    CacheLoadConfig  ( module_t *, FILE * );
     sizeof(int), sizeof(void *), *(uint8_t *)&(uint16_t){ 0xbe1e }, vlc_CPU()
 
 
+void CacheDelete( vlc_object_t *obj, const char *dir )
+{
+    char *path;
+
+    assert( dir != NULL );
+
+    if( asprintf( &path, "%s"DIR_SEP CACHENAME_FORMAT,
+                  dir, CACHENAME_VALUES ) == -1 )
+        return;
+    msg_Dbg( obj, "removing plugins cache file %s", path );
+    utf8_unlink( path );
+    free( path );
+}
+
 /*****************************************************************************
  * LoadPluginsCache: loads the plugins cache file
  *****************************************************************************
@@ -76,9 +90,9 @@ static int    CacheLoadConfig  ( module_t *, FILE * );
  * actually load the dynamically loadable module.
  * This allows us to only fully load plugins when they are actually used.
  *****************************************************************************/
-void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, bool b_delete )
+void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
 {
-    char *psz_filename, *psz_cachedir = config_GetUserDir(VLC_CACHE_DIR);
+    char *psz_filename;
     FILE *file;
     int j, i_size, i_read;
     char p_cachestring[sizeof("cache " COPYRIGHT_MESSAGE)];
@@ -86,27 +100,14 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, bool b_delete )
     module_cache_t **pp_cache = NULL;
     int32_t i_file_size, i_marker;
 
-    if( !psz_cachedir ) /* XXX: this should never happen */
-    {
-        msg_Err( p_this, "Unable to get cache directory" );
-        return;
-    }
+    assert( dir != NULL );
 
-    if( asprintf( &psz_filename, "%s"DIR_SEP CACHENAME_FORMAT,
-                  psz_cachedir, CACHENAME_VALUES ) == -1 )
-    {
-        free( psz_cachedir );
+    if( !p_bank->b_cache )
         return;
-    }
-    free( psz_cachedir );
 
-    if( b_delete )
-    {
-        msg_Dbg( p_this, "removing plugins cache file %s", psz_filename );
-        utf8_unlink( psz_filename );
-        free( psz_filename );
+    if( asprintf( &psz_filename, "%s"DIR_SEP CACHENAME_FORMAT,
+                  dir, CACHENAME_VALUES ) == -1 )
         return;
-    }
 
     msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
 
index 8c4d009e0d5a4417228ebf137d2707d531e74571..2dcf303236488fe1d01563b597a10de1a35a79c7 100644 (file)
@@ -200,7 +200,7 @@ void module_EndBank( vlc_object_t *p_this, bool b_plugins )
  * \param p_this vlc object structure
  * \return nothing
  */
-void module_LoadPlugins( vlc_object_t * p_this, bool b_cache_delete )
+void module_LoadPlugins( vlc_object_t * p_this )
 {
     module_bank_t *p_bank = p_module_bank;
 
@@ -213,8 +213,6 @@ void module_LoadPlugins( vlc_object_t * p_this, bool b_cache_delete )
         msg_Dbg( p_this, "checking plugin modules" );
         p_module_bank->b_cache = var_InheritBool( p_this, "plugins-cache" );
 
-        if( p_module_bank->b_cache || b_cache_delete )
-            CacheLoad( p_this, p_module_bank, b_cache_delete );
         AllocateAllPlugins( p_this, p_module_bank );
         if( p_module_bank->b_cache )
             CacheSave( p_this, p_bank );
@@ -836,6 +834,7 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
     int count,i;
     char * path;
     vlc_array_t *arraypaths = vlc_array_new();
+    const bool b_reset = var_InheritBool( p_this, "reset-plugins-cache" );
 
     /* Contruct the special search path for system that have a relocatable
      * executable. Set it to <vlc path>/modules and <vlc path>/plugins. */
@@ -866,6 +865,11 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
         if( !path )
             continue;
 
+        if( b_reset )
+            CacheDelete( p_this, path );
+        else
+            CacheLoad( p_this, p_module_bank, path );
+
         msg_Dbg( p_this, "recursively browsing `%s'", path );
 
         /* Don't go deeper than 5 subdirectories */
index 62a79ad443b9a0d5aae15946e2d852a923b71330..7469832f3ee299b7f3628b3b89f28eb1e00a185d 100644 (file)
@@ -144,8 +144,8 @@ module_t *vlc_submodule_create (module_t *module);
 
 #define module_InitBank(a)     __module_InitBank(VLC_OBJECT(a))
 void  __module_InitBank        ( vlc_object_t * );
-void module_LoadPlugins( vlc_object_t *, bool );
-#define module_LoadPlugins(a,b) module_LoadPlugins(VLC_OBJECT(a),b)
+void module_LoadPlugins( vlc_object_t * );
+#define module_LoadPlugins(a) module_LoadPlugins(VLC_OBJECT(a))
 void module_EndBank( vlc_object_t *, bool );
 #define module_EndBank(a,b) module_EndBank(VLC_OBJECT(a), b)
 
@@ -158,7 +158,8 @@ void module_Unload (module_handle_t);
 
 /* Plugins cache */
 void   CacheMerge (vlc_object_t *, module_t *, module_t *);
-void   CacheLoad  (vlc_object_t *, module_bank_t *, bool);
+void   CacheDelete(vlc_object_t *, const char *);
+void   CacheLoad  (vlc_object_t *, module_bank_t *, const char *);
 void   CacheSave  (vlc_object_t *, module_bank_t *);
 module_cache_t * CacheFind (module_bank_t *, const char *, int64_t, int64_t);