From 99994a55cd8e6e8f1a1df2beb2f5b5a6b6142e1c Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 5 Sep 2004 03:49:45 +0000 Subject: [PATCH] split out FilenameDB::DelFileSet --- stepmania/src/RageUtil_FileDB.cpp | 46 ++++++++++++++++++------------- stepmania/src/RageUtil_FileDB.h | 1 + 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index 9123c52f36..b72e820518 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -324,31 +324,39 @@ void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv ) } while( begin != end ); } +/* Remove the given FileSet, and all dirp pointers to it. This means the cache has + * expired, not that the directory is necessarily gone; don't actually delete the file + * from the parent. */ +void FilenameDB::DelFileSet( map::iterator dir ) +{ + if( dir == dirs.end() ) + return; + + FileSet *fs = dir->second; + + /* Remove any stale dirp pointers. */ + for( map::iterator it = dirs.begin(); it != dirs.end(); ++it ) + { + FileSet *Clean = it->second; + for( set::iterator f = Clean->files.begin(); f != Clean->files.end(); ++f ) + { + File &ff = (File &) *f; + if( ff.dirp == fs ) + ff.dirp = NULL; + } + } + + delete fs; + dirs.erase( dir ); +} + void FilenameDB::DelFile( const CString &sPath ) { CString lower = sPath; lower.MakeLower(); map::iterator fsi = dirs.find( lower ); - if( fsi != dirs.end() ) - { - FileSet *fs = fsi->second; - - /* Remove any stale dirp pointers. */ - for( map::iterator it = dirs.begin(); it != dirs.end(); ++it ) - { - FileSet *Clean = it->second; - for( set::iterator f = Clean->files.begin(); f != Clean->files.end(); ++f ) - { - File &ff = (File &) *f; - if( ff.dirp == fs ) - ff.dirp = NULL; - } - } - - delete fs; - dirs.erase( fsi ); - } + DelFileSet( fsi ); /* Delete sPath from its parent. */ CString Dir, Name; diff --git a/stepmania/src/RageUtil_FileDB.h b/stepmania/src/RageUtil_FileDB.h index dbe27478ae..e76ed65b59 100644 --- a/stepmania/src/RageUtil_FileDB.h +++ b/stepmania/src/RageUtil_FileDB.h @@ -81,6 +81,7 @@ protected: const CString &beginning, const CString &containing, const CString &ending, vector &out, bool bOnlyDirs); void AddFileSet( CString sPath, FileSet *fs ); + void DelFileSet( map::iterator dir ); /* The given path wasn't cached. Cache it. */ virtual void PopulateFileSet( FileSet &fs, const CString &sPath ) { }