From 93a00528e6634a0996f20826dc1a895364890a80 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 21 May 2005 04:32:35 +0000 Subject: [PATCH] fix GetDirListing("/*") returning "/" (blank file) --- stepmania/src/RageFileManager.cpp | 10 +++++-- stepmania/src/RageUtil_FileDB.cpp | 47 +++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 466378d954..d457dc6b2e 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -156,9 +156,13 @@ public: void LoadFromDrivers( const vector &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(); 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; @@ -230,7 +234,7 @@ RageFileManager::RageFileManager( CString argv0 ) g_Mountpoints = new RageFileDriverMountpoints; LoadedDriver ld; ld.driver = g_Mountpoints; - ld.MountPoint = ""; + ld.MountPoint = "/"; g_Drivers.push_back( ld ); /* 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 ); /* 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 ) { diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index 3d74a06969..8708b7664a 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -15,33 +15,42 @@ void FileSet::GetFilesMatching(const CString &beginning, const CString &containi set::const_iterator i = files.lower_bound( File(beginning) ); 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, * we're past all possible matches in the sort, so stop. */ - if(beginning.size() > i->name.size()) break; /* can't start with it */ - if(strnicmp(i->name, beginning, beginning.size())) break; /* doesn't start with it */ + if( beginning.size() > f.name.size() ) + break; /* can't start with it */ + if( strnicmp(i->name, beginning, beginning.size()) ) + break; /* doesn't start with it */ /* 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. */ - if(end_pos < 0) continue; /* can't end with it */ - if( stricmp(i->name.c_str()+end_pos, ending) ) continue; /* doesn't end with it */ + if( end_pos < 0 ) + 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 * search instead of string match). */ - if(containing.size()) + if( containing.size() ) { - CString name = i->name; + CString name = f.name; name.ToLower(); size_t pos = name.find( containing_lower, beginning.size() ); - if(pos == name.npos) continue; /* doesn't contain it */ - if(pos + containing.size() > unsigned(end_pos)) continue; /* found it but it overlaps with the end */ + if( pos == name.npos ) + 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 * 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; + if( sPath[0] != '/' ) + sPath = "/" + sPath; + vector parts; split( sPath, "/", parts, false ); @@ -377,11 +391,14 @@ void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv ) else --end; + /* Skip the leading slash. */ + ++begin; + do { /* Combine all but the last part. */ - CString dir = join( "/", begin, end-1 ); - if( dir != "" ) + CString dir = "/" + join( "/", begin, end-1 ); + if( dir != "/" ) dir += "/"; const CString &fn = *(end-1); FileSet *fs = GetFileSet( dir );