added: new winix function: mount
displaying all mount points changed: struct Cur has now 'mount' pointer we should not use system->mounts.pmount now (it will be removed in the future) changed: all mount point parameters are now propagated to childs mount points (if not defined there) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@745 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -34,6 +34,7 @@ App::App()
|
||||
// temporary there is only one request
|
||||
cur.request = &req;
|
||||
cur.session = session_manager.GetTmpSession();
|
||||
cur.mount = system.mounts.GetEmptyMount();
|
||||
|
||||
db.SetConn(db_conn);
|
||||
|
||||
@@ -215,7 +216,7 @@ void App::ProcessRequestThrow()
|
||||
plugin.Call(WINIX_SESSION_CHANGED);
|
||||
|
||||
functions.Parse(); // parsing directories,files,functions and parameters
|
||||
system.mounts.CalcCurMount();
|
||||
cur.mount = system.mounts.CalcCurMount();
|
||||
|
||||
if( system.mounts.pmount->type != system.mounts.MountTypeStatic() )
|
||||
Make();
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "request.h"
|
||||
#include "session.h"
|
||||
#include "mount.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -21,6 +22,7 @@ struct Cur
|
||||
{
|
||||
Request * request;
|
||||
Session * session;
|
||||
Mount * mount;
|
||||
|
||||
// those pointers are never null, if there is no a session for the user
|
||||
// the 'session' pointer pointers at a special temporary session
|
||||
|
@@ -208,7 +208,6 @@ size_t level = 0;
|
||||
if( i == dir_tab.End() ||
|
||||
i->parent_id == id ) // means a loop (something wrong in the db)
|
||||
{
|
||||
// we don't change path if there is no such a directory
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -221,6 +220,30 @@ size_t level = 0;
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::IsChild(long parent_id, long child_id)
|
||||
{
|
||||
if( child_id == parent_id )
|
||||
return false;
|
||||
|
||||
DirContainer::Iterator i;
|
||||
|
||||
while( child_id != -1 )
|
||||
{
|
||||
i = dir_tab.FindId(child_id);
|
||||
|
||||
if( i == dir_tab.End() )
|
||||
return false;
|
||||
|
||||
if( i->parent_id == parent_id )
|
||||
return true;
|
||||
|
||||
child_id = i->parent_id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
|
||||
{
|
||||
return dir_tab.ChangeParent(dir_id, new_parent_id);
|
||||
|
@@ -83,6 +83,9 @@ public:
|
||||
// "/abc/def" -> 2
|
||||
size_t DirLevel(long id);
|
||||
|
||||
// checking if child_id is really a child of parent_id
|
||||
bool IsChild(long parent_id, long child_id);
|
||||
|
||||
private:
|
||||
|
||||
Cur * cur;
|
||||
|
@@ -360,7 +360,84 @@ void MountParser::ReadMountParams()
|
||||
|
||||
|
||||
|
||||
void MountParser::ReadRow(std::map<long, Mount> & output)
|
||||
void MountParser::AddParams(Mount::Param & src, Mount::Param & dst)
|
||||
{
|
||||
if( src.size() != dst.size() )
|
||||
{
|
||||
log << log1 << "MP: addparams: incorrect sizes" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
for(size_t p=0 ; p < src.size() ; ++p)
|
||||
{
|
||||
if( src[p].defined && !dst[p].defined )
|
||||
dst[p] = src[p];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool MountParser::AddParamsBefore(long dir_id)
|
||||
{
|
||||
std::map<long, Mount>::iterator i = poutput->find(dir_id);
|
||||
|
||||
if( i == poutput->end() )
|
||||
return false;
|
||||
|
||||
AddParams(i->second.param, mount_inserted.first->second.param);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
adding all non-existing parameters to this mount point from parents
|
||||
*/
|
||||
void MountParser::AddParamsBefore()
|
||||
{
|
||||
if( !pdir )
|
||||
return;
|
||||
|
||||
Item * dir;
|
||||
long dir_id = pdir->parent_id;
|
||||
|
||||
while( dir_id != -1 )
|
||||
{
|
||||
if( AddParamsBefore(dir_id) )
|
||||
{
|
||||
// we don't have to check others parents
|
||||
// the parameters are already copied
|
||||
break;
|
||||
}
|
||||
|
||||
dir = dirs->GetDir(dir_id);
|
||||
|
||||
if( !dir )
|
||||
break;
|
||||
|
||||
dir_id = dir->parent_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
adding all non-existing parameters to childs (childs to this mount point)
|
||||
*/
|
||||
void MountParser::AddParamsAfter()
|
||||
{
|
||||
std::map<long, Mount>::iterator i = poutput->begin();
|
||||
|
||||
for( ; i != poutput->end() ; ++i)
|
||||
{
|
||||
if( dirs->IsChild(mount_inserted.first->second.dir_id, i->first) )
|
||||
AddParams(mount_inserted.first->second.param, i->second.param);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MountParser::ReadRow()
|
||||
{
|
||||
if( ReadMountType() && ReadMountPoint() && ReadFs() )
|
||||
{
|
||||
@@ -373,13 +450,19 @@ void MountParser::ReadRow(std::map<long, Mount> & output)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::pair<std::map<long, Mount>::iterator, bool> res = output.insert( std::make_pair(mount.dir_id, mount) );
|
||||
|
||||
if( !res.second )
|
||||
mount_inserted = poutput->insert( std::make_pair(mount.dir_id, mount) );
|
||||
|
||||
if( mount_inserted.second )
|
||||
{
|
||||
AddParamsBefore();
|
||||
AddParamsAfter();
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "MP: this mount point exists (skipped)" << logend;
|
||||
slog << logwarning << T("mount_exists") << ": " << last_dir << " (" << T("skipped") << ")" << logend;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,13 +480,14 @@ void MountParser::Parse(const std::wstring & input, std::map<long, Mount> & outp
|
||||
return;
|
||||
}
|
||||
|
||||
pinput = input.c_str();
|
||||
pinput = input.c_str();
|
||||
poutput = &output;
|
||||
mount.param.resize(mount_par_tab->size());
|
||||
mount.ClearParams();
|
||||
output.clear();
|
||||
poutput->clear();
|
||||
|
||||
while( *pinput )
|
||||
ReadRow(output);
|
||||
ReadRow();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -64,7 +64,11 @@ private:
|
||||
bool ReadFs();
|
||||
void LogMountParams();
|
||||
void ReadMountParams();
|
||||
void ReadRow(std::map<long, Mount> & output);
|
||||
void ReadRow();
|
||||
void AddParams(Mount::Param & src, Mount::Param & dst);
|
||||
bool AddParamsBefore(long dir_id);
|
||||
void AddParamsBefore();
|
||||
void AddParamsAfter();
|
||||
|
||||
const wchar_t * pinput;
|
||||
std::wstring temp;
|
||||
@@ -73,6 +77,8 @@ private:
|
||||
Mount::ParamRow::ParamArg param_args;
|
||||
Mount mount;
|
||||
Item * pdir;
|
||||
std::map<long, Mount> * poutput;
|
||||
std::pair<std::map<long, Mount>::iterator, bool> mount_inserted;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -253,7 +253,7 @@ void Mounts::MountCmsForRoot()
|
||||
|
||||
|
||||
|
||||
void Mounts::CalcCurMount()
|
||||
Mount * Mounts::CalcCurMount()
|
||||
{
|
||||
std::vector<Item*>::reverse_iterator i;
|
||||
|
||||
@@ -262,7 +262,7 @@ std::vector<Item*>::reverse_iterator i;
|
||||
// when the program starts (when the dir_tab is empty()
|
||||
// we don't want to call MountCmsForRoot()
|
||||
if( cur->request->dir_tab.empty() )
|
||||
return;
|
||||
return pmount;
|
||||
|
||||
for(i = cur->request->dir_tab.rbegin() ; i!=cur->request->dir_tab.rend() ; ++i)
|
||||
{
|
||||
@@ -273,7 +273,7 @@ std::vector<Item*>::reverse_iterator i;
|
||||
pmount = &(m->second);
|
||||
log << log2 << "M: current mount point is: " << GetMountType(pmount->type)
|
||||
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
||||
return;
|
||||
return pmount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,6 +282,8 @@ std::vector<Item*>::reverse_iterator i;
|
||||
MountCmsForRoot();
|
||||
log << log2 << "M: current mount point is: " << GetMountType(pmount->type) << " (default)"
|
||||
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
||||
|
||||
return pmount;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,3 +314,7 @@ const Mounts::MountTab * Mounts::GetMountTab()
|
||||
}
|
||||
|
||||
|
||||
Mount * Mounts::GetEmptyMount()
|
||||
{
|
||||
return &empty_mount;
|
||||
}
|
||||
|
@@ -92,16 +92,22 @@ public:
|
||||
void ReadMounts(const std::wstring & mounts);
|
||||
Error ReadMounts();
|
||||
|
||||
void CalcCurMount();
|
||||
Mount * CalcCurMount();
|
||||
Mount * CalcMount(long dir_id);
|
||||
|
||||
// current mount point
|
||||
// will not be null after calling CalcCurMount() or ReadMounts([...])
|
||||
// !! nie korzystac obecnie z niego
|
||||
// korzystac z cur->mount
|
||||
// a tez zostanie wycofany
|
||||
Mount * pmount;
|
||||
|
||||
|
||||
const MountTab * GetMountTab();
|
||||
|
||||
// at the beginning used to initialize cur->mount
|
||||
Mount * GetEmptyMount();
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
|
Reference in New Issue
Block a user