add recursive redirect lookup

This commit is contained in:
Chris Danford
2005-03-11 06:09:56 +00:00
parent 155b380d2e
commit 2c0f0d1e06
+19 -6
View File
@@ -614,12 +614,15 @@ void StripCrnl(CString &s)
}
/* 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" )
{
CString path2 = path;
return path2;
return path;
}
CString sNewFileName = GetRedirContents( path );
@@ -634,10 +637,20 @@ CString DerefRedir(const CString &path)
CollapsePath( path2 );
if( !DoesFileExist(path2) )
RageException::Throw( "The redirect '%s' references a file '%s' which doesn't exist.", path.c_str(), path2.c_str() );
path2 += "*";
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. */