fix and clean up CreateDirectories
This commit is contained in:
@@ -26,7 +26,7 @@ static int DoMkdir( const CString &sPath, int perm )
|
|||||||
{
|
{
|
||||||
#if defined(XBOX)
|
#if defined(XBOX)
|
||||||
CString TempPath = sPath;
|
CString TempPath = sPath;
|
||||||
TempPath.Replace( "/", "\\" ); /* just for mkdir */
|
TempPath.Replace( "/", "\\" );
|
||||||
return mkdir( TempPath, perm );
|
return mkdir( TempPath, perm );
|
||||||
#else
|
#else
|
||||||
return mkdir( sPath, perm );
|
return mkdir( sPath, perm );
|
||||||
@@ -37,19 +37,30 @@ static int DoOpen( const CString &sPath, int flags, int perm )
|
|||||||
{
|
{
|
||||||
#if defined(XBOX)
|
#if defined(XBOX)
|
||||||
CString TempPath = sPath;
|
CString TempPath = sPath;
|
||||||
TempPath.Replace( "/", "\\" ); /* just for mkdir */
|
TempPath.Replace( "/", "\\" );
|
||||||
return open( TempPath, flags, perm );
|
return open( TempPath, flags, perm );
|
||||||
#else
|
#else
|
||||||
return open( sPath, flags, perm );
|
return open( sPath, flags, perm );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int DoStat( const CString &sPath, struct stat *st )
|
||||||
|
{
|
||||||
|
#if defined(XBOX)
|
||||||
|
CString TempPath = sPath;
|
||||||
|
TempPath.Replace( "/", "\\" );
|
||||||
|
return stat( sPath, st );
|
||||||
|
#else
|
||||||
|
return stat( sPath, st );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
static HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd )
|
static HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd )
|
||||||
{
|
{
|
||||||
#if defined(XBOX)
|
#if defined(XBOX)
|
||||||
CString TempPath = sPath;
|
CString TempPath = sPath;
|
||||||
TempPath.Replace( "/", "\\" ); /* just for mkdir */
|
TempPath.Replace( "/", "\\" );
|
||||||
return FindFirstFile( TempPath, fd );
|
return FindFirstFile( TempPath, fd );
|
||||||
#else
|
#else
|
||||||
return FindFirstFile( sPath, fd );
|
return FindFirstFile( sPath, fd );
|
||||||
@@ -204,6 +215,15 @@ static bool CreateDirectories( CString Path )
|
|||||||
for(unsigned i = 0; i < parts.size(); ++i)
|
for(unsigned i = 0; i < parts.size(); ++i)
|
||||||
{
|
{
|
||||||
curpath += parts[i] + "/";
|
curpath += parts[i] + "/";
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
if( i == 0 && curpath.size() > 1 && curpath[1] == ':' )
|
||||||
|
{
|
||||||
|
/* Don't try to create the drive letter alone. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if( DoMkdir(curpath, 0755) == 0 )
|
if( DoMkdir(curpath, 0755) == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -213,23 +233,18 @@ static bool CreateDirectories( CString Path )
|
|||||||
// Log the error, but continue on.
|
// Log the error, but continue on.
|
||||||
/* When creating a directory that already exists over Samba, Windows is
|
/* When creating a directory that already exists over Samba, Windows is
|
||||||
* returning ENOENT instead of EEXIST. */
|
* returning ENOENT instead of EEXIST. */
|
||||||
/* On Win32 when Path is only a drive letter (e.g. "i:\"), the result is
|
|
||||||
* EINVAL. */
|
|
||||||
if( LOG )
|
if( LOG )
|
||||||
LOG->Warn("Couldn't create %s: %s", curpath.c_str(), strerror(errno) );
|
LOG->Warn("Couldn't create %s: %s", curpath.c_str(), strerror(errno) );
|
||||||
|
|
||||||
/* Make sure it's a directory. */
|
/* Make sure it's a directory. */
|
||||||
FlushDirCache();
|
struct stat st;
|
||||||
if( !IsADirectory(curpath) )
|
DoStat( curpath, &st );
|
||||||
|
if( !(st.st_mode & S_IFDIR) )
|
||||||
{
|
{
|
||||||
if( LOG )
|
if( LOG )
|
||||||
LOG->Warn("Couldn't create %s: path exists and is not a directory", curpath.c_str() );
|
LOG->Warn("Couldn't create %s: path exists and is not a directory", curpath.c_str() );
|
||||||
|
|
||||||
// HACK: IsADirectory doesn't work if Path contains a drive letter.
|
return false;
|
||||||
// So, ignore IsADirectory's result and continue trying to create
|
|
||||||
// directories anyway. This shouldn't change behavior, but
|
|
||||||
// is inefficient because we don't bail early on an error.
|
|
||||||
//return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user