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:
parent
55cd813141
commit
fac60a197b
|
@ -103,7 +103,6 @@ void Config::AssignValues()
|
||||||
data.db_pass = Text("db_pass");
|
data.db_pass = Text("db_pass");
|
||||||
data.base_url = Text("base_url");
|
data.base_url = Text("base_url");
|
||||||
data.one_item_is_showed = Bool("one_item_is_showed");
|
data.one_item_is_showed = Bool("one_item_is_showed");
|
||||||
data.dirs.root.default_item = Int("dir.root.default_item");
|
|
||||||
|
|
||||||
data.priv_no_user = Text("priv_no_user");
|
data.priv_no_user = Text("priv_no_user");
|
||||||
data.priv_no_group = Text("priv_no_group");
|
data.priv_no_group = Text("priv_no_group");
|
||||||
|
|
|
@ -154,22 +154,26 @@ void Content::LogUser()
|
||||||
void Content::MakeDirectoryStructure()
|
void Content::MakeDirectoryStructure()
|
||||||
{
|
{
|
||||||
GetTable::size_type get_table_len = request.get_table.size();
|
GetTable::size_type get_table_len = request.get_table.size();
|
||||||
long parent = -1;
|
get_index = 0;
|
||||||
|
request.dir = -1;
|
||||||
|
|
||||||
for( get_index = 0 ; get_index < get_table_len ; ++get_index)
|
Item * pdir;
|
||||||
|
if( !data.dirs.GetRootDir(&pdir) )
|
||||||
|
// there is no a root dir
|
||||||
|
return;
|
||||||
|
|
||||||
|
request.dir = pdir->id;
|
||||||
|
|
||||||
|
for( ; get_index < get_table_len ; ++get_index)
|
||||||
{
|
{
|
||||||
Item * pdir;
|
if( !data.dirs.GetDir(request.get_table[get_index], pdir->id, &pdir) )
|
||||||
|
|
||||||
if( !data.dirs.GetDir(request.get_table[get_index], parent, &pdir) )
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
parent = pdir->id;
|
|
||||||
request.cur_dir_table.push_back( *pdir );
|
request.cur_dir_table.push_back( *pdir );
|
||||||
}
|
}
|
||||||
|
|
||||||
// parent - last directory (or -1 if none)
|
request.dir = pdir->id;
|
||||||
request.dir = parent;
|
data.dirs.GetDirChilds(request.dir, request.dir_table);
|
||||||
data.dirs.GetDirChilds(parent, request.dir_table);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,7 +247,7 @@ bool Content::MakeGetCheckDir()
|
||||||
long default_id = -1;
|
long default_id = -1;
|
||||||
if( request.cur_dir_table.empty() )
|
if( request.cur_dir_table.empty() )
|
||||||
{
|
{
|
||||||
default_id = data.dirs.root.default_item;
|
//default_id = data.dirs.root.default_item;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -932,7 +932,7 @@ void Db::GetDirs(DirContainer & dir_table)
|
||||||
AssertConnection();
|
AssertConnection();
|
||||||
|
|
||||||
std::ostringstream query;
|
std::ostringstream query;
|
||||||
query << "select * from core.item left join core.content on item.content_id = content.id where type='0';";
|
query << "select * from core.item where type='0';";
|
||||||
|
|
||||||
r = AssertQuery( query.str() );
|
r = AssertQuery( query.str() );
|
||||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||||
|
@ -954,7 +954,6 @@ void Db::GetDirs(DirContainer & dir_table)
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearResult(r);
|
ClearResult(r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,17 @@
|
||||||
|
|
||||||
DirContainer::DirContainer()
|
DirContainer::DirContainer()
|
||||||
{
|
{
|
||||||
|
is_root = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DirContainer::Iterator DirContainer::GetRoot()
|
||||||
|
{
|
||||||
|
if( !is_root )
|
||||||
|
return table.end();
|
||||||
|
|
||||||
|
return table.begin() + root_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +51,7 @@ bool DirContainer::Empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DirContainer::PushBack(const Item & item)
|
void DirContainer::PushBack(const Item & item)
|
||||||
{
|
{
|
||||||
bool rebuild_indexes = false;
|
bool rebuild_indexes = false;
|
||||||
|
@ -47,8 +59,21 @@ bool rebuild_indexes = false;
|
||||||
if( table.size() == table.capacity() )
|
if( table.size() == table.capacity() )
|
||||||
rebuild_indexes = true;
|
rebuild_indexes = true;
|
||||||
|
|
||||||
|
|
||||||
|
if( item.parent_id == -1 )
|
||||||
|
{
|
||||||
|
if( is_root )
|
||||||
|
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
is_root = true;
|
||||||
|
root_index = table.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table.push_back(item);
|
table.push_back(item);
|
||||||
log << log2 << "DirCont: added item, id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
log << log2 << "DirCont: added item, id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
||||||
|
|
||||||
|
|
||||||
if( rebuild_indexes )
|
if( rebuild_indexes )
|
||||||
RebuildIndexes();
|
RebuildIndexes();
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
|
|
||||||
DirContainer();
|
DirContainer();
|
||||||
|
|
||||||
|
Iterator GetRoot();
|
||||||
|
|
||||||
Iterator Begin();
|
Iterator Begin();
|
||||||
Iterator End();
|
Iterator End();
|
||||||
SizeType Size();
|
SizeType Size();
|
||||||
|
@ -57,6 +59,12 @@ private:
|
||||||
// main table with dirs
|
// main table with dirs
|
||||||
Table table;
|
Table table;
|
||||||
|
|
||||||
|
// true if there is a root dir in the table
|
||||||
|
bool is_root;
|
||||||
|
|
||||||
|
// root dir
|
||||||
|
SizeType root_index;
|
||||||
|
|
||||||
// indexes
|
// indexes
|
||||||
TableId table_id;
|
TableId table_id;
|
||||||
TableParent table_parent;
|
TableParent table_parent;
|
||||||
|
|
|
@ -13,21 +13,55 @@
|
||||||
void Dirs::Clear()
|
void Dirs::Clear()
|
||||||
{
|
{
|
||||||
dir_table.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()
|
void Dirs::ReadDirs()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
db.GetDirs(dir_table);
|
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)
|
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)
|
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;
|
std::string name;
|
||||||
const char * s = path.c_str();
|
const char * s = path.c_str();
|
||||||
Item * pitem = &root;
|
|
||||||
|
|
||||||
while( ExtractName(s, name) )
|
while( ExtractName(s, name) )
|
||||||
{
|
{
|
||||||
if( !GetDir(name, parent, &pitem) )
|
if( !GetDir(name, pitem->id, &pitem) )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*item = pitem;
|
*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)
|
bool Dirs::GetDirId(const std::string & path, long * id)
|
||||||
{
|
{
|
||||||
Item * pitem;
|
Item * pitem;
|
||||||
|
@ -111,10 +154,6 @@ return true;
|
||||||
|
|
||||||
bool Dirs::IsDir(long id)
|
bool Dirs::IsDir(long id)
|
||||||
{
|
{
|
||||||
if( id == -1 )
|
|
||||||
// root directory
|
|
||||||
return true;
|
|
||||||
|
|
||||||
DirContainer::Iterator i = dir_table.FindId(id);
|
DirContainer::Iterator i = dir_table.FindId(id);
|
||||||
|
|
||||||
if( i == dir_table.End() )
|
if( i == dir_table.End() )
|
||||||
|
@ -128,7 +167,7 @@ return true;
|
||||||
|
|
||||||
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
|
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
|
||||||
{
|
{
|
||||||
if( !IsDir(parent) )
|
if( parent != -1 && !IsDir(parent) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||||
|
@ -150,21 +189,23 @@ bool Dirs::MakePath(long id, std::string & path)
|
||||||
{
|
{
|
||||||
DirContainer::Iterator i;
|
DirContainer::Iterator i;
|
||||||
|
|
||||||
path.clear();
|
path = '/';
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
if( id == -1 )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
i = dir_table.FindId(id);
|
i = dir_table.FindId(id);
|
||||||
|
|
||||||
if( i == dir_table.End() )
|
if( i == dir_table.End() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if( i->parent_id == -1 )
|
||||||
|
return true;
|
||||||
|
|
||||||
id = i->parent_id;
|
id = i->parent_id;
|
||||||
path.insert(path.begin(), '/');
|
|
||||||
|
|
||||||
path.insert(0, i->url);
|
path.insert(0, i->url);
|
||||||
|
path.insert(path.begin(), '/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
core/dirs.h
17
core/dirs.h
|
@ -29,21 +29,12 @@ private:
|
||||||
public: // !! temporarily
|
public: // !! temporarily
|
||||||
|
|
||||||
|
|
||||||
// id = -1;
|
|
||||||
Item root;
|
|
||||||
|
|
||||||
|
|
||||||
DirContainer dir_table;
|
DirContainer dir_table;
|
||||||
|
|
||||||
|
|
||||||
// parent (or -1), item
|
|
||||||
//typedef std::multimap<long, Item> DirTable;
|
|
||||||
//DirTable dir_table;
|
|
||||||
|
|
||||||
|
|
||||||
bool ExtractName(const char * & s, std::string & name);
|
bool ExtractName(const char * & s, std::string & name);
|
||||||
|
void CheckRootDir();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -57,6 +48,8 @@ public:
|
||||||
|
|
||||||
bool IsDir(long id);
|
bool IsDir(long id);
|
||||||
|
|
||||||
|
bool GetRootDir(Item ** item);
|
||||||
|
|
||||||
bool GetDir(const std::string & path, Item ** item);
|
bool GetDir(const std::string & path, Item ** item);
|
||||||
bool GetDir(const std::string & name, long parent, Item ** item);
|
bool GetDir(const std::string & name, long parent, Item ** item);
|
||||||
|
|
||||||
|
|
|
@ -384,7 +384,7 @@ bool Request::HasAccess(const Item & item, int mask)
|
||||||
|
|
||||||
if( session->puser && session->puser->IsMemberOf(item.group_id) )
|
if( session->puser && session->puser->IsMemberOf(item.group_id) )
|
||||||
{
|
{
|
||||||
// group
|
// group
|
||||||
return ((item.privileges >> 3) & mask) == mask;
|
return ((item.privileges >> 3) & mask) == mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ bool Request::HasReadWriteAccess(const Item & item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Request::HasExecAccess(const Item & item)
|
bool Request::HasReadExecAccess(const Item & item)
|
||||||
{
|
{
|
||||||
return HasAccess(item, 5); // r+x
|
return HasAccess(item, 5); // r+x
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ struct Request
|
||||||
bool HasReadAccess(const Item & item);
|
bool HasReadAccess(const Item & item);
|
||||||
bool HasWriteAccess(const Item & item);
|
bool HasWriteAccess(const Item & item);
|
||||||
bool HasReadWriteAccess(const Item & item);
|
bool HasReadWriteAccess(const Item & item);
|
||||||
bool HasExecAccess(const Item & item);
|
bool HasReadExecAccess(const Item & item);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue