add FilenameDB::AddFile

This commit is contained in:
Glenn Maynard
2003-12-08 00:04:47 +00:00
parent 58c65bec3b
commit d62570c1fc
2 changed files with 42 additions and 5 deletions
+38
View File
@@ -241,6 +241,44 @@ void FilenameDB::AddFileSet( CString sPath, FileSet *fs )
dirs[sPath] = fs; dirs[sPath] = fs;
} }
/* 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 mtime )
{
vector<CString> parts;
split( sPath, "/", parts, false );
CStringArray::const_iterator begin = parts.begin();
CStringArray::const_iterator end = parts.end();
bool IsDir = true;
if( sPath[sPath.size()-1] != '/' )
IsDir = false;
else
--end;
do
{
/* Combine all but the last part. */
CString dir = join( "/", begin, end-1 ) + "/";
const CString &fn = *(end-1);
FileSet &fs = GetFileSet( dir );
File f;
f.SetName( fn );
if( fs.files.find( f ) == fs.files.end() )
{
f.dir = IsDir;
f.size = size;
f.mtime = mtime;
fs.files.insert( f );
}
IsDir = true;
--end;
} while( begin != end );
}
void FilenameDB::FlushDirCache() void FilenameDB::FlushDirCache()
{ {
for( map<CString, FileSet *>::iterator i = dirs.begin(); i != dirs.end(); ++i ) for( map<CString, FileSet *>::iterator i = dirs.begin(); i != dirs.end(); ++i )
+4 -5
View File
@@ -73,18 +73,17 @@ protected:
void GetFilesMatching(const CString &dir, void GetFilesMatching(const CString &dir,
const CString &beginning, const CString &containing, const CString &ending, const CString &beginning, const CString &containing, const CString &ending,
vector<CString> &out, bool bOnlyDirs); vector<CString> &out, bool bOnlyDirs);
void AddFileSet( CString sPath, FileSet *fs );
/* The given path wasn't cached. Cache it, and return the cached FileSet or /* The given path wasn't cached. Cache it. */
* NULL on failure. */ virtual void PopulateFileSet( FileSet &fs, const CString &sPath ) { }
virtual void PopulateFileSet( FileSet &fs, const CString &sPath ) = 0;
public: public:
FilenameDB::FilenameDB(): FilenameDB::FilenameDB():
ExpireSeconds( -1 ) { } ExpireSeconds( -1 ) { }
virtual FilenameDB::~FilenameDB() { FlushDirCache(); } virtual FilenameDB::~FilenameDB() { FlushDirCache(); }
void AddFileSet( CString sPath, FileSet *fs ); void AddFile( const CString &sPath, int size, int mtime );
/* This handles at most two * wildcards. If we need anything more complicated, /* This handles at most two * wildcards. If we need anything more complicated,
* we'll need to use fnmatch or regex. */ * we'll need to use fnmatch or regex. */