added: cp function for directories
added: emacs/mkdir uses group_id of the parent directory when creating new items added: parameter 'dirls' to ls function git-svn-id: svn://ttmath.org/publicrep/winix/trunk@606 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
192
content/cp.cpp
192
content/cp.cpp
@@ -24,8 +24,13 @@ bool Content::CpCheckAccessFrom()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
if( !request.IsParam("r") )
|
||||
{
|
||||
// directories need 'r' parameter
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
// dirs are checked in function parser
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -53,46 +58,197 @@ void Content::CpAuth(Item & item)
|
||||
}
|
||||
|
||||
|
||||
void Content::CpItem(Item & item, bool redirect)
|
||||
void Content::CpSetNewAttributes(Item & item)
|
||||
{
|
||||
if( MoveIsTheSameFile(item) )
|
||||
return;
|
||||
|
||||
if( !mv_file.empty() )
|
||||
{
|
||||
item.url = mv_file;
|
||||
PrepareUrl(item);
|
||||
}
|
||||
|
||||
item.parent_id = mv_dir_id;
|
||||
item.user_id = cp_new_user;
|
||||
item.group_id = cp_new_group;
|
||||
item.SetDateModifyToNow();
|
||||
}
|
||||
|
||||
|
||||
void Content::CpItem(Item & item, long dst_dir_id)
|
||||
{
|
||||
if( !request.HasReadAccess(item) )
|
||||
return; // !! w przyszlosci bedziemy dodawac komunikaty do specjalnej tablicy (narazie nie zaimplementowane)
|
||||
|
||||
item.parent_id = dst_dir_id;
|
||||
|
||||
if( !cp_preserve_attr )
|
||||
CpSetNewAttributes(item);
|
||||
|
||||
PostFunEmacsAdd(item);
|
||||
|
||||
if( request.status == WINIX_ERR_OK )
|
||||
{
|
||||
if( item.auth != Item::auth_none )
|
||||
CpAuth(item);
|
||||
|
||||
if( redirect )
|
||||
RedirectTo(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::CpPrepare()
|
||||
{
|
||||
cp_iq.SetAll(true, false);
|
||||
cp_iq.WhereType(Item::file);
|
||||
|
||||
cp_new_user = -1;
|
||||
cp_new_group = -1;
|
||||
|
||||
if( request.session->puser )
|
||||
cp_new_user = request.session->puser->id;
|
||||
|
||||
Item * pdir = data.dirs.GetDir(mv_dir_id);
|
||||
|
||||
if( pdir )
|
||||
cp_new_group = pdir->group_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::CpFilesInDir(const Item & dir, long dst_dir_id)
|
||||
{
|
||||
cp_iq.WhereParentId(dir.id);
|
||||
db.GetItems(request.item_table, cp_iq);
|
||||
|
||||
for(size_t i=0 ; i<request.item_table.size() ; ++i)
|
||||
CpItem(request.item_table[i], dst_dir_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::CpContentOfDir(const Item & item, long dst_dir_id)
|
||||
{
|
||||
DirContainer::ParentIterator i = data.dirs.FindFirstParent(item.id);
|
||||
|
||||
// go through all directories
|
||||
for( ; i != data.dirs.ParentEnd() ; i = data.dirs.NextParent(i) )
|
||||
CpDir(*(i->second), dst_dir_id);
|
||||
|
||||
CpFilesInDir(item, dst_dir_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// we shouldn't change 'item' because we have references to our data.dirs objects
|
||||
long Content::CpDir(const Item & item, long dst_dir_id)
|
||||
{
|
||||
cp_temp = item;
|
||||
cp_temp.parent_id = dst_dir_id;
|
||||
|
||||
if( !mv_file.empty() )
|
||||
{
|
||||
cp_temp.url = mv_file;
|
||||
mv_file.clear();
|
||||
PrepareUrl(cp_temp);
|
||||
}
|
||||
|
||||
if( !cp_preserve_attr )
|
||||
CpSetNewAttributes(cp_temp);
|
||||
|
||||
if( cp_remove_defaults )
|
||||
cp_temp.default_item = -1;
|
||||
|
||||
Mkdir(cp_temp, false);
|
||||
long new_dir_id = cp_temp.id; // remember the new dir_id
|
||||
|
||||
if( request.HasReadExecAccess(item) )
|
||||
CpContentOfDir(item, cp_temp.id);
|
||||
|
||||
return new_dir_id; // and return it
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// here 'item' can be changed in place
|
||||
void Content::CpItemCheck(Item & item, bool redirect)
|
||||
{
|
||||
if( MoveIsTheSameFile(item) )
|
||||
return;
|
||||
|
||||
if( !mv_file.empty() )
|
||||
{
|
||||
item.url = mv_file;
|
||||
PrepareUrl(item);
|
||||
}
|
||||
|
||||
CpItem(item, mv_dir_id);
|
||||
|
||||
if( request.status==WINIX_ERR_OK && redirect )
|
||||
RedirectTo(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::CpContentOfDirCheck(const Item & item, bool redirect)
|
||||
{
|
||||
if( !mv_file.empty() )
|
||||
{
|
||||
request.status = WINIX_ERR_INCORRECT_DIR;
|
||||
return;
|
||||
}
|
||||
|
||||
if( mv_dir_id == item.id )
|
||||
return; // nothing to do
|
||||
|
||||
if( data.dirs.HasParent(mv_dir_id, item.id) )
|
||||
{
|
||||
log << log1 << "Content: cannot copy directory to inside it" << logend;
|
||||
request.status = WINIX_ERR_INCORRECT_DIR;
|
||||
return;
|
||||
}
|
||||
|
||||
CpContentOfDir(item, mv_dir_id);
|
||||
|
||||
if( request.status==WINIX_ERR_OK && redirect )
|
||||
RedirectTo(mv_dir_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::CpDirCheck(const Item & item, bool redirect)
|
||||
{
|
||||
if( mv_file.empty() && mv_dir_id == item.id )
|
||||
return; // nothing to do
|
||||
|
||||
if( mv_dir_id == item.id || data.dirs.HasParent(mv_dir_id, item.id) )
|
||||
{
|
||||
log << log1 << "Content: cannot copy directory to inside it" << logend;
|
||||
request.status = WINIX_ERR_INCORRECT_DIR;
|
||||
return;
|
||||
}
|
||||
|
||||
long new_dir_id = CpDir(item, mv_dir_id);
|
||||
|
||||
if( request.status==WINIX_ERR_OK && redirect )
|
||||
RedirectTo(new_dir_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunCp()
|
||||
{
|
||||
if( CpCheckAccessFrom() &&
|
||||
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
|
||||
MoveCheckAccessTo(mv_dir_id) )
|
||||
{
|
||||
CpPrepare();
|
||||
cp_preserve_attr = request.IsPostVar("preserveattr");
|
||||
|
||||
if( request.is_item )
|
||||
{
|
||||
CpItem(request.item);
|
||||
CpItemCheck(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* not implemented yet */
|
||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||
cp_remove_defaults = request.IsPostVar("removedefaults");
|
||||
|
||||
if( request.IsPostVar("onlycontent") )
|
||||
CpContentOfDirCheck(*request.dir_table.back());
|
||||
else
|
||||
CpDirCheck(*request.dir_table.back());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user