fix GetDirListing("/*") returning "/" (blank file)

This commit is contained in:
Glenn Maynard
2005-05-21 04:32:35 +00:00
parent 948567aab1
commit 93a00528e6
2 changed files with 39 additions and 18 deletions
+7 -3
View File
@@ -156,9 +156,13 @@ public:
void LoadFromDrivers( const vector<LoadedDriver> &drivers ) void LoadFromDrivers( const vector<LoadedDriver> &drivers )
{ {
/* XXX: Even though these two operations lock on their own, lock around
* them, too. That way, nothing can sneak in and get incorrect
* results between the flush and the re-population. */
FDB->FlushDirCache(); FDB->FlushDirCache();
for( unsigned i = 0; i < drivers.size(); ++i ) for( unsigned i = 0; i < drivers.size(); ++i )
FDB->AddFile( drivers[i].MountPoint, 0, 0 ); if( drivers[i].MountPoint != "/" )
FDB->AddFile( drivers[i].MountPoint, 0, 0 );
} }
}; };
static RageFileDriverMountpoints *g_Mountpoints = NULL; static RageFileDriverMountpoints *g_Mountpoints = NULL;
@@ -230,7 +234,7 @@ RageFileManager::RageFileManager( CString argv0 )
g_Mountpoints = new RageFileDriverMountpoints; g_Mountpoints = new RageFileDriverMountpoints;
LoadedDriver ld; LoadedDriver ld;
ld.driver = g_Mountpoints; ld.driver = g_Mountpoints;
ld.MountPoint = ""; ld.MountPoint = "/";
g_Drivers.push_back( ld ); g_Drivers.push_back( ld );
/* The mount path is unused, but must be nonempty. */ /* The mount path is unused, but must be nonempty. */
@@ -357,7 +361,7 @@ void RageFileManager::GetDirListing( CString sPath, CStringArray &AddTo, bool bO
ld.driver->GetDirListing( p, AddTo, bOnlyDirs, bReturnPathToo ); ld.driver->GetDirListing( p, AddTo, bOnlyDirs, bReturnPathToo );
/* If returning the path, prepend the mountpoint name to the files this driver returned. */ /* If returning the path, prepend the mountpoint name to the files this driver returned. */
if( bReturnPathToo ) if( bReturnPathToo && ld.MountPoint.size() > 0 )
{ {
for( unsigned j = OldStart; j < AddTo.size(); ++j ) for( unsigned j = OldStart; j < AddTo.size(); ++j )
{ {
+32 -15
View File
@@ -15,33 +15,42 @@ void FileSet::GetFilesMatching(const CString &beginning, const CString &containi
set<File>::const_iterator i = files.lower_bound( File(beginning) ); set<File>::const_iterator i = files.lower_bound( File(beginning) );
for( ; i != files.end(); ++i) for( ; i != files.end(); ++i)
{ {
if(bOnlyDirs && !i->dir) continue; const File &f = *i;
if( bOnlyDirs && !f.dir )
continue;
/* Check beginning. Once we hit a filename that no longer matches beginning, /* Check beginning. Once we hit a filename that no longer matches beginning,
* we're past all possible matches in the sort, so stop. */ * we're past all possible matches in the sort, so stop. */
if(beginning.size() > i->name.size()) break; /* can't start with it */ if( beginning.size() > f.name.size() )
if(strnicmp(i->name, beginning, beginning.size())) break; /* doesn't start with it */ break; /* can't start with it */
if( strnicmp(i->name, beginning, beginning.size()) )
break; /* doesn't start with it */
/* Position the end starts on: */ /* Position the end starts on: */
int end_pos = int(i->name.size())-int(ending.size()); int end_pos = int(f.name.size())-int(ending.size());
/* Check end. */ /* Check end. */
if(end_pos < 0) continue; /* can't end with it */ if( end_pos < 0 )
if( stricmp(i->name.c_str()+end_pos, ending) ) continue; /* doesn't end with it */ continue; /* can't end with it */
if( stricmp(f.name.c_str()+end_pos, ending) )
continue; /* doesn't end with it */
/* Check containing. Do this last, since it's the slowest (substring /* Check containing. Do this last, since it's the slowest (substring
* search instead of string match). */ * search instead of string match). */
if(containing.size()) if( containing.size() )
{ {
CString name = i->name; CString name = f.name;
name.ToLower(); name.ToLower();
size_t pos = name.find( containing_lower, beginning.size() ); size_t pos = name.find( containing_lower, beginning.size() );
if(pos == name.npos) continue; /* doesn't contain it */ if( pos == name.npos )
if(pos + containing.size() > unsigned(end_pos)) continue; /* found it but it overlaps with the end */ continue; /* doesn't contain it */
if( pos + containing.size() > unsigned(end_pos) )
continue; /* found it but it overlaps with the end */
} }
out.push_back( i->name ); out.push_back( f.name );
} }
} }
@@ -360,11 +369,16 @@ FileSet *FilenameDB::GetFileSet( CString dir, bool create )
/* Add the file or directory "sPath". sPath is a directory if it ends with /* Add the file or directory "sPath". sPath is a directory if it ends with
* a slash. */ * a slash. */
void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv ) void FilenameDB::AddFile( const CString &sPath_, int size, int hash, void *priv )
{ {
if( sPath == "" ) CString sPath(sPath_);
if( sPath == "" || sPath == "/" )
return; return;
if( sPath[0] != '/' )
sPath = "/" + sPath;
vector<CString> parts; vector<CString> parts;
split( sPath, "/", parts, false ); split( sPath, "/", parts, false );
@@ -377,11 +391,14 @@ void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv )
else else
--end; --end;
/* Skip the leading slash. */
++begin;
do do
{ {
/* Combine all but the last part. */ /* Combine all but the last part. */
CString dir = join( "/", begin, end-1 ); CString dir = "/" + join( "/", begin, end-1 );
if( dir != "" ) if( dir != "/" )
dir += "/"; dir += "/";
const CString &fn = *(end-1); const CString &fn = *(end-1);
FileSet *fs = GetFileSet( dir ); FileSet *fs = GetFileSet( dir );