add FilenameDB::DelFile
This commit is contained in:
@@ -109,8 +109,8 @@ FileType FilenameDB::GetFileType( const CString &sPath )
|
|||||||
if( Name == "." )
|
if( Name == "." )
|
||||||
return TTYPE_DIR;
|
return TTYPE_DIR;
|
||||||
|
|
||||||
FileSet &fs = GetFileSet( Dir );
|
FileSet *fs = GetFileSet( Dir );
|
||||||
return fs.GetFileType( Name );
|
return fs->GetFileType( Name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,16 +118,16 @@ int FilenameDB::GetFileSize( const CString &sPath )
|
|||||||
{
|
{
|
||||||
CString Dir, Name;
|
CString Dir, Name;
|
||||||
SplitPath(sPath, Dir, Name);
|
SplitPath(sPath, Dir, Name);
|
||||||
FileSet &fs = GetFileSet( Dir );
|
FileSet *fs = GetFileSet( Dir );
|
||||||
return fs.GetFileSize(Name);
|
return fs->GetFileSize(Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FilenameDB::GetFileHash( const CString &sPath )
|
int FilenameDB::GetFileHash( const CString &sPath )
|
||||||
{
|
{
|
||||||
CString Dir, Name;
|
CString Dir, Name;
|
||||||
SplitPath(sPath, Dir, Name);
|
SplitPath(sPath, Dir, Name);
|
||||||
FileSet &fs = GetFileSet( Dir );
|
FileSet *fs = GetFileSet( Dir );
|
||||||
return fs.GetFileHash(Name);
|
return fs->GetFileHash(Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilenameDB::ResolvePath(CString &path)
|
bool FilenameDB::ResolvePath(CString &path)
|
||||||
@@ -150,7 +150,7 @@ bool FilenameDB::ResolvePath(CString &path)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if( fs == NULL )
|
if( fs == NULL )
|
||||||
fs = &GetFileSet( ret );
|
fs = GetFileSet( ret );
|
||||||
|
|
||||||
CString p = path.substr( begin, size );
|
CString p = path.substr( begin, size );
|
||||||
set<File>::iterator it = fs->files.find( File(p) );
|
set<File>::iterator it = fs->files.find( File(p) );
|
||||||
@@ -179,14 +179,14 @@ bool FilenameDB::ResolvePath(CString &path)
|
|||||||
|
|
||||||
void FilenameDB::GetFilesMatching(const CString &dir, const CString &beginning, const CString &containing, const CString &ending, vector<CString> &out, bool bOnlyDirs)
|
void FilenameDB::GetFilesMatching(const CString &dir, const CString &beginning, const CString &containing, const CString &ending, vector<CString> &out, bool bOnlyDirs)
|
||||||
{
|
{
|
||||||
FileSet &fs = GetFileSet( dir );
|
FileSet *fs = GetFileSet( dir );
|
||||||
fs.GetFilesMatching(beginning, containing, ending, out, bOnlyDirs);
|
fs->GetFilesMatching(beginning, containing, ending, out, bOnlyDirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilenameDB::GetFilesEqualTo(const CString &dir, const CString &fn, vector<CString> &out, bool bOnlyDirs)
|
void FilenameDB::GetFilesEqualTo(const CString &dir, const CString &fn, vector<CString> &out, bool bOnlyDirs)
|
||||||
{
|
{
|
||||||
FileSet &fs = GetFileSet( dir );
|
FileSet *fs = GetFileSet( dir );
|
||||||
fs.GetFilesEqualTo(fn, out, bOnlyDirs);
|
fs->GetFilesEqualTo(fn, out, bOnlyDirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ void FilenameDB::GetFilesSimpleMatch(const CString &dir, const CString &fn, vect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSet &FilenameDB::GetFileSet( CString dir )
|
FileSet *FilenameDB::GetFileSet( CString dir, bool create )
|
||||||
{
|
{
|
||||||
/* Normalize the path. */
|
/* Normalize the path. */
|
||||||
dir.Replace("\\", "/"); /* foo\bar -> foo/bar */
|
dir.Replace("\\", "/"); /* foo\bar -> foo/bar */
|
||||||
@@ -228,6 +228,13 @@ FileSet &FilenameDB::GetFileSet( CString dir )
|
|||||||
lower.MakeLower();
|
lower.MakeLower();
|
||||||
|
|
||||||
map<CString, FileSet *>::iterator i = dirs.find( lower );
|
map<CString, FileSet *>::iterator i = dirs.find( lower );
|
||||||
|
if( !create )
|
||||||
|
{
|
||||||
|
if( i == dirs.end() )
|
||||||
|
return NULL;
|
||||||
|
return i->second;
|
||||||
|
}
|
||||||
|
|
||||||
FileSet *ret;
|
FileSet *ret;
|
||||||
if( i != dirs.end() )
|
if( i != dirs.end() )
|
||||||
{
|
{
|
||||||
@@ -237,7 +244,7 @@ FileSet &FilenameDB::GetFileSet( CString dir )
|
|||||||
ret->age.Touch();
|
ret->age.Touch();
|
||||||
ret->files.clear();
|
ret->files.clear();
|
||||||
} else
|
} else
|
||||||
return *i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -246,7 +253,7 @@ FileSet &FilenameDB::GetFileSet( CString dir )
|
|||||||
}
|
}
|
||||||
|
|
||||||
PopulateFileSet( *ret, dir );
|
PopulateFileSet( *ret, dir );
|
||||||
return *ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilenameDB::AddFileSet( CString sPath, FileSet *fs )
|
void FilenameDB::AddFileSet( CString sPath, FileSet *fs )
|
||||||
@@ -280,11 +287,11 @@ void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv )
|
|||||||
/* Combine all but the last part. */
|
/* Combine all but the last part. */
|
||||||
CString dir = join( "/", begin, end-1 ) + "/";
|
CString dir = join( "/", begin, end-1 ) + "/";
|
||||||
const CString &fn = *(end-1);
|
const CString &fn = *(end-1);
|
||||||
FileSet &fs = GetFileSet( dir );
|
FileSet *fs = GetFileSet( dir );
|
||||||
|
|
||||||
File f;
|
File f;
|
||||||
f.SetName( fn );
|
f.SetName( fn );
|
||||||
if( fs.files.find( f ) == fs.files.end() )
|
if( fs->files.find( f ) == fs->files.end() )
|
||||||
{
|
{
|
||||||
f.dir = IsDir;
|
f.dir = IsDir;
|
||||||
if( !IsDir )
|
if( !IsDir )
|
||||||
@@ -293,7 +300,7 @@ void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv )
|
|||||||
f.hash = hash;
|
f.hash = hash;
|
||||||
f.priv = priv;
|
f.priv = priv;
|
||||||
}
|
}
|
||||||
fs.files.insert( f );
|
fs->files.insert( f );
|
||||||
}
|
}
|
||||||
IsDir = true;
|
IsDir = true;
|
||||||
|
|
||||||
@@ -301,6 +308,43 @@ void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv )
|
|||||||
} while( begin != end );
|
} while( begin != end );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilenameDB::DelFile( const CString &sPath )
|
||||||
|
{
|
||||||
|
CString lower = sPath;
|
||||||
|
lower.MakeLower();
|
||||||
|
|
||||||
|
map<CString, FileSet *>::iterator fsi = dirs.find( lower );
|
||||||
|
if( fsi != dirs.end() )
|
||||||
|
{
|
||||||
|
FileSet *fs = fsi->second;
|
||||||
|
|
||||||
|
/* Remove any stale dirp pointers. */
|
||||||
|
for( map<CString, FileSet *>::iterator it = dirs.begin(); it != dirs.end(); ++it )
|
||||||
|
{
|
||||||
|
FileSet *Clean = it->second;
|
||||||
|
for( set<File>::iterator f = Clean->files.begin(); f != Clean->files.end(); ++f )
|
||||||
|
if( f->dirp == fs )
|
||||||
|
f->dirp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete fs;
|
||||||
|
dirs.erase( fsi );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete sPath from its parent. */
|
||||||
|
CString Dir, Name;
|
||||||
|
SplitPath(sPath, Dir, Name);
|
||||||
|
FileSet *Parent = GetFileSet( Dir, false );
|
||||||
|
if( Parent )
|
||||||
|
{
|
||||||
|
set<File>::iterator i = Parent->files.find( File(Name) );
|
||||||
|
if( i != Parent->files.end() )
|
||||||
|
{
|
||||||
|
Parent->files.erase( i );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 )
|
||||||
@@ -312,11 +356,11 @@ File *FilenameDB::GetFile( const CString &sPath )
|
|||||||
{
|
{
|
||||||
CString Dir, Name;
|
CString Dir, Name;
|
||||||
SplitPath(sPath, Dir, Name);
|
SplitPath(sPath, Dir, Name);
|
||||||
FileSet &fs = GetFileSet( Dir );
|
FileSet *fs = GetFileSet( Dir );
|
||||||
|
|
||||||
set<File>::iterator it;
|
set<File>::iterator it;
|
||||||
it = fs.files.find( File(Name) );
|
it = fs->files.find( File(Name) );
|
||||||
if( it == fs.files.end() )
|
if( it == fs->files.end() )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Oops. &*it is a const File &, because you can't change the order
|
/* Oops. &*it is a const File &, because you can't change the order
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ struct FileSet
|
|||||||
class FilenameDB
|
class FilenameDB
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
FileSet &GetFileSet( CString dir );
|
FileSet *GetFileSet( CString dir, bool create=true );
|
||||||
|
|
||||||
/* Directories we have cached: */
|
/* Directories we have cached: */
|
||||||
map<CString, FileSet *> dirs;
|
map<CString, FileSet *> dirs;
|
||||||
@@ -92,6 +92,7 @@ public:
|
|||||||
virtual FilenameDB::~FilenameDB() { FlushDirCache(); }
|
virtual FilenameDB::~FilenameDB() { FlushDirCache(); }
|
||||||
|
|
||||||
void AddFile( const CString &sPath, int size, int hash, void *priv=NULL );
|
void AddFile( const CString &sPath, int size, int hash, void *priv=NULL );
|
||||||
|
void DelFile( const CString &sPath );
|
||||||
File *GetFile( const CString &path );
|
File *GetFile( const CString &path );
|
||||||
|
|
||||||
/* This handles at most two * wildcards. If we need anything more complicated,
|
/* This handles at most two * wildcards. If we need anything more complicated,
|
||||||
|
|||||||
Reference in New Issue
Block a user