Commit 2ec9fb75 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Load/delete plugins cache from plugins directory

Also refactor. Deletion and loading are now distinct functions.
parent a16618e4
......@@ -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;
......
......@@ -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 );
......
......@@ -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 */
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment