From 2ec9fb757e42b1b534fe6d66e93a2d39ee5955b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 30 Jan 2010 23:32:54 +0200 Subject: [PATCH] Load/delete plugins cache from plugins directory Also refactor. Deletion and loading are now distinct functions. --- src/libvlc.c | 5 +---- src/modules/cache.c | 39 ++++++++++++++++++++------------------- src/modules/modules.c | 10 +++++++--- src/modules/modules.h | 7 ++++--- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/libvlc.c b/src/libvlc.c index 7f7bed61f1..3ffade5173 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -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; diff --git a/src/modules/cache.c b/src/modules/cache.c index a872adc335..d8efe76b09 100644 --- a/src/modules/cache.c +++ b/src/modules/cache.c @@ -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 ); diff --git a/src/modules/modules.c b/src/modules/modules.c index 8c4d009e0d..2dcf303236 100644 --- a/src/modules/modules.c +++ b/src/modules/modules.c @@ -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 /modules and /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 */ diff --git a/src/modules/modules.h b/src/modules/modules.h index 62a79ad443..7469832f3e 100644 --- a/src/modules/modules.h +++ b/src/modules/modules.h @@ -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); -- 2.39.2