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 )
{
bool result = true;
char *tmpdir = tempnam( NULL, "vlt" );
string tempPath = tmpdir;
string tempPath = sFromLocale( tmpdir );
free( tmpdir );
// Extract the file in a temporary directory
......@@ -311,7 +311,7 @@ bool ThemeLoader::extract( const string &fileName )
list<string>::const_iterator 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;
}
}
......@@ -410,10 +410,10 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
DIR *pCurrDir;
struct dirent *pDirContent;
char *pszDirContent;
// Open the dir
pCurrDir = opendir( rootDir.c_str() );
pCurrDir = utf8_opendir( rootDir.c_str() );
if( pCurrDir == NULL )
{
......@@ -422,22 +422,20 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
return false;
}
// Get the first directory entry
pDirContent = (dirent*)readdir( pCurrDir );
// 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 ..
if( string( pDirContent->d_name ) != "." &&
string( pDirContent->d_name ) != ".." )
if( string( pszDirContent ) != "." &&
string( pszDirContent ) != ".." )
{
#if defined( S_ISDIR )
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 )
if( pDirContent->d_type & DT_DIR )
#else
......@@ -447,6 +445,7 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
// Can we find the file in this subdirectory?
if( findFile( newURI, rFileName, themeFilePath ) )
{
free( pszDirContent );
closedir( pCurrDir );
return true;
}
......@@ -454,16 +453,17 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
else
{
// Found the theme file?
if( rFileName == string( pDirContent->d_name ) )
if( rFileName == string( pszDirContent ) )
{
themeFilePath = sFromLocale( newURI );
themeFilePath = newURI;
free( pszDirContent );
closedir( pCurrDir );
return true;
}
}
}
pDirContent = (dirent*)readdir( pCurrDir );
free( pszDirContent );
}
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