add recursive redirect lookup
This commit is contained in:
@@ -614,18 +614,21 @@ void StripCrnl(CString &s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* path is a .redir pathname. Read it and return the real one. */
|
/* path is a .redir pathname. Read it and return the real one. */
|
||||||
CString DerefRedir(const CString &path)
|
CString DerefRedir(const CString &_path)
|
||||||
{
|
{
|
||||||
|
CString path = _path;
|
||||||
|
|
||||||
|
for( int i=0; i<100; i++ )
|
||||||
|
{
|
||||||
if( GetExtension(path) != "redir" )
|
if( GetExtension(path) != "redir" )
|
||||||
{
|
{
|
||||||
CString path2 = path;
|
return path;
|
||||||
return path2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CString sNewFileName = GetRedirContents( path );
|
CString sNewFileName = GetRedirContents( path );
|
||||||
|
|
||||||
/* Empty is invalid. */
|
/* Empty is invalid. */
|
||||||
if(sNewFileName == "")
|
if( sNewFileName == "" )
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
FixSlashesInPlace( sNewFileName );
|
FixSlashesInPlace( sNewFileName );
|
||||||
@@ -634,10 +637,20 @@ CString DerefRedir(const CString &path)
|
|||||||
|
|
||||||
CollapsePath( path2 );
|
CollapsePath( path2 );
|
||||||
|
|
||||||
if( !DoesFileExist(path2) )
|
path2 += "*";
|
||||||
RageException::Throw( "The redirect '%s' references a file '%s' which doesn't exist.", path.c_str(), path2.c_str() );
|
|
||||||
|
|
||||||
return path2;
|
vector<CString> matches;
|
||||||
|
GetDirListing( path2, matches, false, true );
|
||||||
|
|
||||||
|
if( matches.empty() )
|
||||||
|
RageException::Throw( "The redirect '%s' references a file '%s' which doesn't exist.", path.c_str(), path2.c_str() );
|
||||||
|
else if( matches.size() > 1 )
|
||||||
|
RageException::Throw( "The redirect '%s' references a file '%s' with multiple matches.", path.c_str(), path2.c_str() );
|
||||||
|
|
||||||
|
path = matches[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
RageException::Throw( "Circular redirect '%s'", path.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: This can be used to read one line from any file; rename it. */
|
/* XXX: This can be used to read one line from any file; rename it. */
|
||||||
|
|||||||
Reference in New Issue
Block a user