From 61449225d8d700446822548239298f99bded0b10 Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sun, 9 Sep 2007 17:27:07 +0000 Subject: [PATCH] XDG Base Directory Specification fix. I wasn't using the XDG_CACHE_HOME variable for the cache directory. Thanks to ILEoo for noticing. --- include/main.h | 3 ++- src/input/meta.c | 10 +++++----- src/libvlc-common.c | 2 ++ src/modules/configuration.c | 34 ++++++++++++++++++++++++++++++++-- src/modules/configuration.h | 1 + src/modules/modules.c | 20 ++++++++++---------- 6 files changed, 52 insertions(+), 18 deletions(-) diff --git a/include/main.h b/include/main.h index df0d190b5d..69e290db18 100644 --- a/include/main.h +++ b/include/main.h @@ -41,7 +41,8 @@ struct libvlc_int_t char * psz_homedir; ///< user's home directory char * psz_configdir; ///< user's configuration directory - char * psz_datadir; ///< user's data/cache directory + char * psz_datadir; ///< user's data directory + char * psz_cachedir; ///< user's cache directory char * psz_configfile; ///< location of config file diff --git a/src/input/meta.c b/src/input/meta.c index 08f5c5069c..ca318207c5 100644 --- a/src/input/meta.c +++ b/src/input/meta.c @@ -236,10 +236,10 @@ static void ArtCacheCreateDir( const char *psz_dir ) { while( *psz && *psz != DIR_SEP_CHAR) psz++; if( !*psz ) break; - *psz = 0; + *psz = 0; if( !EMPTY_STR( psz_newdir ) ) utf8_mkdir( psz_newdir ); *psz = DIR_SEP_CHAR; - psz++; + psz++; } utf8_mkdir( psz_dir ); } @@ -275,7 +275,7 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj, snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s", - p_obj->p_libvlc->psz_datadir, + p_obj->p_libvlc->psz_cachedir, psz_artist_sanitized, psz_album_sanitized ); free( psz_album_sanitized ); free( psz_artist_sanitized ); @@ -285,7 +285,7 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj, char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title ); snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP "art" DIR_SEP "title" DIR_SEP "%s", - p_obj->p_libvlc->psz_datadir, + p_obj->p_libvlc->psz_cachedir, psz_title_sanitized ); free( psz_title_sanitized ); } @@ -417,7 +417,7 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) } psz_type = strrchr( psz_arturl, '.' ); - if( strlen( psz_type ) > 5 ) + if( strlen( psz_type ) > 5 ) psz_type = NULL; /* remove extension if it's > to 4 characters */ /* Warning: psz_title, psz_artist, psz_album may change in ArtCache*() */ diff --git a/src/libvlc-common.c b/src/libvlc-common.c index 01be53e76c..af6982f554 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -328,6 +328,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) p_libvlc->psz_homedir = config_GetHomeDir(); p_libvlc->psz_configdir = config_GetConfigDir( p_libvlc ); p_libvlc->psz_datadir = config_GetUserDataDir( p_libvlc ); + p_libvlc->psz_cachedir = config_GetCacheDir( p_libvlc ); p_libvlc->psz_configfile = config_GetCustomConfigFile( p_libvlc ); /* Check for plugins cache options */ @@ -1054,6 +1055,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release ) FREENULL( p_libvlc->psz_homedir ); FREENULL( p_libvlc->psz_configdir ); FREENULL( p_libvlc->psz_datadir ); + FREENULL( p_libvlc->psz_cachedir ); FREENULL( p_libvlc->psz_configfile ); FREENULL( p_libvlc->p_hotkeys ); diff --git a/src/modules/configuration.c b/src/modules/configuration.c index e9f583a7b5..4e74b417ee 100644 --- a/src/modules/configuration.c +++ b/src/modules/configuration.c @@ -1914,8 +1914,8 @@ char *config_GetConfigDir( libvlc_int_t *p_libvlc ) } /** - * Get the user's VLC data and cache directory - * (used for stuff like the modules cache, the album art cache, ...) + * Get the user's VLC data directory + * (used for stuff like the skins, custom lua modules, ...) */ char *config_GetUserDataDir( libvlc_int_t *p_libvlc ) { @@ -1943,6 +1943,36 @@ char *config_GetUserDataDir( libvlc_int_t *p_libvlc ) #endif } +/** + * Get the user's VLC cache directory + * (used for stuff like the modules cache, the album art cache, ...) + */ +char *config_GetCacheDir( libvlc_int_t *p_libvlc ) +{ + char *psz_dir; +#if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) + char *psz_parent = config_GetUserDir(); + if( !psz_parent ) psz_parent = p_libvlc->psz_homedir; + if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) + return NULL; + return psz_dir; +#else + /* XDG Base Directory Specification - Version 0.6 */ + char *psz_env = getenv( "XDG_CACHE_HOME" ); + if( psz_env ) + { + if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 ) + return NULL; + return psz_dir; + } + psz_env = getenv( "HOME" ); + if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */ + if( asprintf( &psz_dir, "%s/.cache/vlc", psz_env ) == -1 ) + return NULL; + return psz_dir; +#endif +} + /** * Get the user's configuration file */ diff --git a/src/modules/configuration.h b/src/modules/configuration.h index f7213169be..f9d1fc6a9a 100644 --- a/src/modules/configuration.h +++ b/src/modules/configuration.h @@ -42,6 +42,7 @@ int __config_LoadCmdLine ( vlc_object_t *, int *, char *[], vlc_bool_t ); char *config_GetHomeDir ( void ); char *config_GetConfigDir ( libvlc_int_t * ); char *config_GetUserDataDir( libvlc_int_t * ); +char *config_GetCacheDir ( libvlc_int_t * ); char *config_GetConfigFile ( libvlc_int_t * ); char *config_GetCustomConfigFile( libvlc_int_t * ); int __config_LoadConfigFile( vlc_object_t *, const char * ); diff --git a/src/modules/modules.c b/src/modules/modules.c index 9cd1c654ea..217ed1cd57 100644 --- a/src/modules/modules.c +++ b/src/modules/modules.c @@ -1665,7 +1665,7 @@ static char * GetWindowsError( void ) *****************************************************************************/ static void CacheLoad( vlc_object_t *p_this ) { - char *psz_filename, *psz_datadir; + char *psz_filename, *psz_cachedir; FILE *file; int i, j, i_size, i_read; char p_cachestring[sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE)]; @@ -1675,15 +1675,15 @@ static void CacheLoad( vlc_object_t *p_this ) int32_t i_file_size, i_marker; libvlc_global_data_t *p_libvlc_global = vlc_global(); - psz_datadir = p_this->p_libvlc->psz_datadir; - if( !psz_datadir ) /* XXX: this should never happen */ + psz_cachedir = p_this->p_libvlc->psz_cachedir; + if( !psz_cachedir ) /* XXX: this should never happen */ { msg_Err( p_this, "Unable to get cache directory" ); return; } i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s", - psz_datadir, PLUGINSCACHE_DIR, CacheName() ); + psz_cachedir, PLUGINSCACHE_DIR, CacheName() ); if( i_size <= 0 ) { msg_Err( p_this, "out of memory" ); @@ -2022,15 +2022,15 @@ static void CacheSave( vlc_object_t *p_this ) "# For information about cache directory tags, see:\r\n" "# http://www.brynosaurus.com/cachedir/\r\n"; - char *psz_filename, *psz_datadir; + char *psz_filename, *psz_cachedir; FILE *file; int i, j, i_cache; module_cache_t **pp_cache; int32_t i_file_size = 0; libvlc_global_data_t *p_libvlc_global = vlc_global(); - psz_datadir = p_this->p_libvlc->psz_datadir; - if( !psz_datadir ) /* XXX: this should never happen */ + psz_cachedir = p_this->p_libvlc->psz_cachedir; + if( !psz_cachedir ) /* XXX: this should never happen */ { msg_Err( p_this, "Unable to get cache directory" ); return; @@ -2038,7 +2038,7 @@ static void CacheSave( vlc_object_t *p_this ) psz_filename = (char *)malloc( sizeof(DIR_SEP PLUGINSCACHE_DIR DIR_SEP ) + - strlen(psz_datadir) + strlen(CacheName()) ); + strlen(psz_cachedir) + strlen(CacheName()) ); if( !psz_filename ) { @@ -2046,7 +2046,7 @@ static void CacheSave( vlc_object_t *p_this ) return; } - sprintf( psz_filename, "%s", psz_datadir ); + sprintf( psz_filename, "%s", psz_cachedir ); config_CreateDir( p_this, psz_filename ); @@ -2063,7 +2063,7 @@ static void CacheSave( vlc_object_t *p_this ) fclose( file ); } - sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s", psz_datadir, + sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s", psz_cachedir, PLUGINSCACHE_DIR, CacheName() ); msg_Dbg( p_this, "saving plugins cache file %s", psz_filename ); -- 2.39.2