changed: DirContainer - uses std::list instead of std::vector as the main container

we do not have to rebuild indexes after deleting some items
added:   DirContainer::DelById(long id)
changed: Dirs::CheckRootDir() addes the root dir if there is no one
added:   Dirs::DeleteDir(long id) - deletes specified directory (and its contents)
         (from the cache and the database)
added:   Db::DelDirById(long id) - deletes a dir from the database 
         and its first children
added:   standard function rm can delete directories


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@487 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-02-06 13:12:03 +00:00
parent 7d73d048c8
commit 951d0e8653
18 changed files with 303 additions and 102 deletions

View File

@@ -19,23 +19,27 @@ void Dirs::Clear()
void Dirs::CheckRootDir()
{
DirContainer::ParentIterator i;
long roots = 0;
for( i=dir_table.FindFirstParent(-1) ; i!=dir_table.ParentEnd() ; i=dir_table.NextParent(i) )
++roots;
if( roots == 0 )
DirContainer::Iterator i = dir_table.GetRoot();
if( i != dir_table.End() )
return;
log << log1 << "Dirs: there is no a root dir in the database (creating one)" << logend;
Item root;
root.type = Item::dir;
root.parent_id = -1;
root.user_id = -1;
root.group_id = -1;
root.privileges = 0755;
root.default_item = -1;
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
// !! zrobic jakis wyjatek do wprowadzania roota?
if( db.AddItem(root) == Error::ok )
{
log << log1 << "Dirs: there is no a root dir in the database" << logend;
Clear();
}
else
if( roots > 1 )
{
log << log1 << "Dirs: there are more than one root dir in the database" << logend;
Clear();
dir_table.PushBack(root);
}
}
@@ -372,3 +376,30 @@ void Dirs::SplitPath(const std::string & path, std::string & dir, std::string &
if( i < path.size() - 1 )
file.assign(path, i+1, path.size() - i - 1);
}
void Dirs::DeleteDir(long id)
{
DirContainer::ParentIterator pnext, p = dir_table.FindFirstParent(id);
for( ; p != dir_table.ParentEnd() ; p = pnext )
{
// this iterator p will be deleted by the next DeleteDir(p->second->id)
// (the next iterator we must calculate beforehand)
pnext = dir_table.NextParent(p);
DeleteDir(p->second->id);
}
if( db.DelDirById(id) == Error::ok )
dir_table.DelById(id);
}