added: to the Item: auth_path - a path to a static file (if auth is different from auth_none)
added: function 'mv' (move) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@596 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
111
core/dirs.cpp
111
core/dirs.cpp
@@ -138,6 +138,7 @@ DirContainer::ParentIterator Dirs::ParentEnd()
|
||||
// dodatkowo moze metoda AppendPath dodajaca sciezke do biezacego stringa?
|
||||
// albo tutaj stringa nie czyscic?
|
||||
// O(m * log n) (m- how many parts are in 'id')
|
||||
// path with a slash at the end
|
||||
bool Dirs::MakePath(long id, std::string & path)
|
||||
{
|
||||
DirContainer::Iterator i;
|
||||
@@ -148,7 +149,8 @@ DirContainer::Iterator i;
|
||||
{
|
||||
i = dir_table.FindId(id);
|
||||
|
||||
if( i == dir_table.End() )
|
||||
if( i == dir_table.End() ||
|
||||
i->parent_id == id ) // means a loop (something wrong in the db)
|
||||
return false;
|
||||
|
||||
if( i->parent_id == -1 )
|
||||
@@ -164,6 +166,34 @@ DirContainer::Iterator i;
|
||||
|
||||
|
||||
|
||||
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
|
||||
{
|
||||
return dir_table.ChangeParent(dir_id, new_parent_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
checking whether dir_id has a parent parent_id (somewhere in the path)
|
||||
*/
|
||||
bool Dirs::HasParent(long dir_id, long parent_id)
|
||||
{
|
||||
DirContainer::Iterator i;
|
||||
|
||||
while( true )
|
||||
{
|
||||
i = dir_table.FindId(dir_id);
|
||||
|
||||
if( i==dir_table.End() || i->parent_id==-1 )
|
||||
return false;
|
||||
|
||||
if( i->parent_id == parent_id )
|
||||
return true;
|
||||
|
||||
dir_id = i->parent_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -249,6 +279,85 @@ Item * Dirs::AddDir(const Item & item)
|
||||
|
||||
|
||||
|
||||
size_t Dirs::AnalyzeDir(Item * pdir, const std::string & path, long & dir_id, std::string & dir)
|
||||
{
|
||||
size_t i = 0;
|
||||
size_t old_i;
|
||||
|
||||
while( true )
|
||||
{
|
||||
dir_id = pdir->id;
|
||||
|
||||
// skipping slashes
|
||||
for( ; i<path.size() && path[i] == '/' ; ++i );
|
||||
|
||||
if( i == path.size() )
|
||||
return i; // end of the path
|
||||
|
||||
// creating a name
|
||||
old_i = i;
|
||||
analyze_temp.clear();
|
||||
|
||||
for( ; i<path.size() && path[i] != '/' ; ++i)
|
||||
analyze_temp += path[i];
|
||||
|
||||
pdir = data.dirs.GetDir(analyze_temp, pdir->id);
|
||||
|
||||
if( !pdir )
|
||||
return old_i; // analyze_temp is not a directory
|
||||
|
||||
dir += analyze_temp;
|
||||
dir += '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
the path should begin with a slash
|
||||
|
||||
return values:
|
||||
0 - directory exists
|
||||
dir_id - id of the directory
|
||||
dir - the path to the directory (with a slash at the end)
|
||||
file - if not empty means a file name (we don't check if the file really exists)
|
||||
1 - there is not a root dir
|
||||
2 - the path is empty
|
||||
3 - there is not such a directory
|
||||
*/
|
||||
int Dirs::AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file)
|
||||
{
|
||||
Item * pdir = data.dirs.GetRootDir();
|
||||
dir = '/';
|
||||
file.clear();
|
||||
|
||||
if( !pdir )
|
||||
return 1;
|
||||
|
||||
if( path.empty() )
|
||||
return 2;
|
||||
|
||||
if( path[0] != '/' )
|
||||
return 3;
|
||||
|
||||
size_t i = AnalyzeDir(pdir, path, dir_id, dir);
|
||||
|
||||
if( i < path.size() )
|
||||
{
|
||||
// checking if at least one slash has left
|
||||
for(size_t a=i ; a < path.size() ; ++a)
|
||||
if( path[a] == '/' )
|
||||
return 3; // there is not such a directory
|
||||
|
||||
// the rest of the path is a file name
|
||||
file = path.c_str() + i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Dirs::SplitPath(const std::string & path, std::string & dir, std::string & file)
|
||||
{
|
||||
|
Reference in New Issue
Block a user