changed: there is one dir called root (has parent_id -1)

(we have an owner, group, privileges etc of the root dir)
         the root.id of course is not -1 


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@468 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2008-12-22 16:03:03 +00:00
parent 55cd813141
commit fac60a197b
9 changed files with 117 additions and 48 deletions

View File

@@ -13,21 +13,55 @@
void Dirs::Clear()
{
dir_table.Clear();
// !! temporarily not clearing
//root.Clear();
root.id = -1;
}
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 )
{
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();
}
}
void Dirs::ReadDirs()
{
Clear();
db.GetDirs(dir_table);
CheckRootDir();
}
bool Dirs::GetRootDir(Item ** item)
{
DirContainer::Iterator root = dir_table.GetRoot();
if( root == dir_table.End() )
return false;
*item = &(*root);
return true;
}
bool Dirs::GetDir(const std::string & name, long parent, Item ** item)
@@ -60,19 +94,27 @@ return !name.empty();
// !! moze lepiej zwracac wskaznik do Item i kiedy nie ma katalogu to zwracac 0 ?
bool Dirs::GetDir(const std::string & path, Item ** item)
{
long parent = -1;
DirContainer::Iterator root = dir_table.GetRoot();
if( root == dir_table.End() )
// ops, we do not have a root dir
return false;
Item * pitem = &(*root);
std::string name;
const char * s = path.c_str();
Item * pitem = &root;
while( ExtractName(s, name) )
{
if( !GetDir(name, parent, &pitem) )
if( !GetDir(name, pitem->id, &pitem) )
return false;
}
*item = pitem;
@@ -81,7 +123,8 @@ return true;
// !! ten interfejs jes bylejaki
// !! moze lepiej zwracac id i kiedy nie ma katalogu to -1 (przeciez to jest wartosc ktora nie moze pojawic sie w indeksie)
bool Dirs::GetDirId(const std::string & path, long * id)
{
Item * pitem;
@@ -111,10 +154,6 @@ return true;
bool Dirs::IsDir(long id)
{
if( id == -1 )
// root directory
return true;
DirContainer::Iterator i = dir_table.FindId(id);
if( i == dir_table.End() )
@@ -128,7 +167,7 @@ return true;
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
{
if( !IsDir(parent) )
if( parent != -1 && !IsDir(parent) )
return false;
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
@@ -150,21 +189,23 @@ bool Dirs::MakePath(long id, std::string & path)
{
DirContainer::Iterator i;
path.clear();
path = '/';
while( true )
{
if( id == -1 )
return true;
i = dir_table.FindId(id);
if( i == dir_table.End() )
return false;
if( i->parent_id == -1 )
return true;
id = i->parent_id;
path.insert(path.begin(), '/');
path.insert(0, i->url);
path.insert(path.begin(), '/');
}
}