Commit 424681e5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Skins2 theme loader:

 - use utf8_(read|open)dir
 - do not assume that stat() succeeds (tiny race condition)
parent 6491b05b
...@@ -278,7 +278,7 @@ bool ThemeLoader::extract( const string &fileName ) ...@@ -278,7 +278,7 @@ bool ThemeLoader::extract( const string &fileName )
{ {
bool result = true; bool result = true;
char *tmpdir = tempnam( NULL, "vlt" ); char *tmpdir = tempnam( NULL, "vlt" );
string tempPath = tmpdir; string tempPath = sFromLocale( tmpdir );
free( tmpdir ); free( tmpdir );
// Extract the file in a temporary directory // Extract the file in a temporary directory
...@@ -311,7 +311,7 @@ bool ThemeLoader::extract( const string &fileName ) ...@@ -311,7 +311,7 @@ bool ThemeLoader::extract( const string &fileName )
list<string>::const_iterator it; list<string>::const_iterator it;
for( it = resPath.begin(); it != resPath.end(); it++ ) for( it = resPath.begin(); it != resPath.end(); it++ )
{ {
if( findFile( sToLocale( *it ), WINAMP2_XML_FILE, xmlFile ) ) if( findFile( *it, WINAMP2_XML_FILE, xmlFile ) )
break; break;
} }
} }
...@@ -410,10 +410,10 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, ...@@ -410,10 +410,10 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
const string &sep = OSFactory::instance( getIntf() )->getDirSeparator(); const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
DIR *pCurrDir; DIR *pCurrDir;
struct dirent *pDirContent; char *pszDirContent;
// Open the dir // Open the dir
pCurrDir = opendir( rootDir.c_str() ); pCurrDir = utf8_opendir( rootDir.c_str() );
if( pCurrDir == NULL ) if( pCurrDir == NULL )
{ {
...@@ -422,22 +422,20 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, ...@@ -422,22 +422,20 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
return false; return false;
} }
// Get the first directory entry
pDirContent = (dirent*)readdir( pCurrDir );
// While we still have entries in the directory // While we still have entries in the directory
while( pDirContent != NULL ) while( ( pszDirContent = utf8_readdir( pCurrDir ) ) != NULL )
{ {
string newURI = rootDir + sep + pDirContent->d_name; string newURI = rootDir + sep + pszDirContent;
// Skip . and .. // Skip . and ..
if( string( pDirContent->d_name ) != "." && if( string( pszDirContent ) != "." &&
string( pDirContent->d_name ) != ".." ) string( pszDirContent ) != ".." )
{ {
#if defined( S_ISDIR ) #if defined( S_ISDIR )
struct stat stat_data; struct stat stat_data;
stat( newURI.c_str(), &stat_data );
if( S_ISDIR(stat_data.st_mode) ) if( ( utf8_stat( newURI.c_str(), &stat_data ) == 0 )
&& S_ISDIR(stat_data.st_mode) )
#elif defined( DT_DIR ) #elif defined( DT_DIR )
if( pDirContent->d_type & DT_DIR ) if( pDirContent->d_type & DT_DIR )
#else #else
...@@ -447,6 +445,7 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, ...@@ -447,6 +445,7 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
// Can we find the file in this subdirectory? // Can we find the file in this subdirectory?
if( findFile( newURI, rFileName, themeFilePath ) ) if( findFile( newURI, rFileName, themeFilePath ) )
{ {
free( pszDirContent );
closedir( pCurrDir ); closedir( pCurrDir );
return true; return true;
} }
...@@ -454,16 +453,17 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, ...@@ -454,16 +453,17 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
else else
{ {
// Found the theme file? // Found the theme file?
if( rFileName == string( pDirContent->d_name ) ) if( rFileName == string( pszDirContent ) )
{ {
themeFilePath = sFromLocale( newURI ); themeFilePath = newURI;
free( pszDirContent );
closedir( pCurrDir ); closedir( pCurrDir );
return true; return true;
} }
} }
} }
pDirContent = (dirent*)readdir( pCurrDir ); free( pszDirContent );
} }
closedir( pCurrDir ); closedir( pCurrDir );
......
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