we can create links (hard links, symbolic links) now
added winix functions: ln winix function 'default' can be used without redirecting now added new tickets types: TypeProgress, TypeString, TypeMultistring, TypeImages, TypeFiles now tickets are combined with files added winix functions: showtickets fixed mountpoints: when the default root mount was created its parameter table was empty and it caused accessing to a non-existing objects fixed logger: modifiers (log1, log2, log3) were incorrectly treated added modifier: log4 (debug info) now we are moving threads to a new plugin 'thread' created directory: plugins/thread (not finished yet) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@704 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
272
functions/rm.cpp
272
functions/rm.cpp
@@ -22,6 +22,7 @@ namespace Fun
|
||||
Rm::Rm()
|
||||
{
|
||||
fun.url = L"rm";
|
||||
follow_symlinks = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +36,10 @@ bool Rm::HasAccess(const Item & item)
|
||||
|
||||
if( item.parent_id == -1 )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !request->session->puser || !request->session->puser->super_user )
|
||||
// we can only remove the content of the root directory
|
||||
// and here we check only access the the root dir
|
||||
// "onlycontent" parameter should be check in post method
|
||||
if( !system->HasWriteAccess(item) )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -72,39 +74,110 @@ return true;
|
||||
|
||||
|
||||
|
||||
void Rm::RemoveAuthPrepareQuery()
|
||||
void Rm::Prepare()
|
||||
{
|
||||
rm_auth_iq.SetAll(true, false);
|
||||
content_dir_iq.SetAll(false, false);
|
||||
content_dir_iq.sel_parent_id = true;
|
||||
content_dir_iq.sel_type = true;
|
||||
content_dir_iq.sel_url = true;
|
||||
content_dir_iq.sel_file = true;
|
||||
|
||||
rm_auth_iq.sel_parent_id = true;
|
||||
rm_auth_iq.sel_type = true;
|
||||
rm_auth_iq.sel_file = true;
|
||||
static_iq.SetAll(false, false);
|
||||
static_iq.sel_parent_id = true;
|
||||
static_iq.sel_type = true;
|
||||
static_iq.sel_url = true;
|
||||
static_iq.sel_file = true;
|
||||
|
||||
rm_auth_iq.WhereType(Item::file);
|
||||
rm_auth_iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE, false);
|
||||
static_iq.WhereType(Item::file);
|
||||
static_iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE, false);
|
||||
}
|
||||
|
||||
|
||||
bool Rm::RemoveStaticFile(const std::wstring & path)
|
||||
{
|
||||
if( ::RemoveFile(path) )
|
||||
{
|
||||
log << log2 << "Rm: removed static file: " << path << logend;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Rm: can't remove a file: " << path << logend;
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Rm::RemoveStaticFile(Item & item)
|
||||
{
|
||||
if( system->MakeFilePath(item, path, false) )
|
||||
{
|
||||
if( RemoveStaticFile(path) )
|
||||
{
|
||||
if( item.has_thumb && system->MakeFilePath(item, path, true) )
|
||||
{
|
||||
RemoveStaticFile(path);
|
||||
item.has_thumb = false;
|
||||
}
|
||||
|
||||
// we don't store it to db (it will be removed or is removed already)
|
||||
item.file_path.clear();
|
||||
item.file_type = WINIX_ITEM_FILETYPE_NONE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rm::RemoveAllDirs(long dir_id)
|
||||
void Rm::RemoveFileOrSymlink(Item & item)
|
||||
{
|
||||
DirContainer::ParentIterator pnext, p = system->dirs.FindFirstParent(dir_id);
|
||||
if( db->DelItem(item) == WINIX_ERR_OK )
|
||||
{
|
||||
if( item.type == Item::file )
|
||||
log << log2 << "Rm: deleted file ";
|
||||
else
|
||||
log << log2 << "Rm: deleted symlink ";
|
||||
|
||||
log << item.url << logend;
|
||||
|
||||
TemplatesFunctions::pattern_cacher.DeletePattern(item);
|
||||
plugin.Call(WINIX_FILE_REMOVED, item.id);
|
||||
db->EditThreadRemoveItem(item.parent_id);
|
||||
|
||||
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
RemoveStaticFile(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
// request->status = WINIX_ERR_NO_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Rm::RemoveDirTree(long dir_id)
|
||||
{
|
||||
DirContainer::ParentIterator pnext, p = system->dirs.FindFirstChild(dir_id);
|
||||
|
||||
for( ; p != system->dirs.ParentEnd() ; p = pnext )
|
||||
{
|
||||
// this iterator p will be deleted by the next DeleteDir(p->second->id)
|
||||
// (the next iterator we must calculate beforehand)
|
||||
pnext = system->dirs.NextParent(p);
|
||||
RemoveAllDirs(p->second->id);
|
||||
pnext = system->dirs.NextChild(p);
|
||||
RemoveDirTree(p->second->id);
|
||||
}
|
||||
|
||||
plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, dir_id);
|
||||
|
||||
rm_auth_iq.WhereParentId(dir_id);
|
||||
db->GetItems(request->item_tab, rm_auth_iq);
|
||||
static_iq.WhereParentId(dir_id);
|
||||
db->GetItems(static_item_tab, static_iq);
|
||||
|
||||
for(size_t i=0 ; i<request->item_tab.size() ; ++i)
|
||||
RemoveStaticFile(request->item_tab[i]);
|
||||
for(size_t i=0 ; i<static_item_tab.size() ; ++i)
|
||||
RemoveStaticFile(static_item_tab[i]);
|
||||
|
||||
if( db->DelDirById(dir_id) == WINIX_ERR_OK )
|
||||
{
|
||||
@@ -117,115 +190,96 @@ void Rm::RemoveAllDirs(long dir_id)
|
||||
|
||||
|
||||
|
||||
void Rm::RemoveAllDirs()
|
||||
void Rm::RemoveDir(const Item & dir)
|
||||
{
|
||||
RemoveAuthPrepareQuery();
|
||||
old_url = dir.url;
|
||||
RemoveDirTree(dir.id);
|
||||
|
||||
// this method deletes recursively all directories
|
||||
RemoveAllDirs(request->dir_tab.back()->id);
|
||||
request->dir_tab.erase(--request->dir_tab.end());
|
||||
|
||||
if( request->dir_tab.empty() )
|
||||
{
|
||||
// we have deleted the root directory
|
||||
system->dirs.CheckRootDir(); // adding a new root dir
|
||||
Item * proot = system->dirs.GetRootDir();
|
||||
|
||||
if( proot )
|
||||
request->dir_tab.push_back(proot);
|
||||
else
|
||||
// there is no a root dir
|
||||
// CheckRootDir() didn't add the root dir (probably problem with the database)
|
||||
// make sure that ::Make() will check that the dir_tab is empty and returns
|
||||
return;
|
||||
}
|
||||
|
||||
system->RedirectToLastDir();
|
||||
}
|
||||
|
||||
|
||||
void Rm::RemoveDir()
|
||||
{
|
||||
if( request->param_tab.empty() )
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED; // use parameter "r" for removing a directory
|
||||
else
|
||||
if( request->IsParam(L"r") )
|
||||
RemoveAllDirs();
|
||||
else
|
||||
request->status = WINIX_ERR_UNKNOWN_PARAM;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rm::RemoveStaticFile(Item & item)
|
||||
{
|
||||
if( item.file_path.empty() )
|
||||
{
|
||||
log << log1 << "Rm: can't remove a static file: file_path is empty" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !system->MakeFilePath(item, path) )
|
||||
return;
|
||||
|
||||
if( ::RemoveFile(path) )
|
||||
{
|
||||
log << log1 << "Rm: removed static file: " << path << logend;
|
||||
item.file_path.clear();
|
||||
item.file_type = WINIX_ITEM_FILETYPE_NONE;
|
||||
// we don't store it to db (will be removed or is removed already)
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Rm: can't remove a file: " << path << logend;
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
log << log3 << "Rm: removed directory " << old_url << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rm::RemoveFile()
|
||||
{
|
||||
// for safety we check if param_tab is empty
|
||||
// a user can use "confirm" but can make a mistake when typing
|
||||
if( !request->param_tab.empty() )
|
||||
{
|
||||
request->status = WINIX_ERR_UNKNOWN_PARAM;
|
||||
return;
|
||||
}
|
||||
RemoveFileOrSymlink(request->item);
|
||||
|
||||
if( db->DelItem( request->item ) )
|
||||
{
|
||||
log << log2 << "Rm: deleted item: subject: " << request->item.subject << ", id: " << request->item.id << logend;
|
||||
TemplatesFunctions::pattern_cacher.DeletePattern(request->item);
|
||||
|
||||
plugin.Call(WINIX_FILE_REMOVED, request->item.id);
|
||||
|
||||
if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
|
||||
db->EditThreadRemoveItem(request->item.parent_id);
|
||||
|
||||
if( request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
RemoveStaticFile(request->item);
|
||||
}
|
||||
else
|
||||
{
|
||||
request->status = WINIX_ERR_NO_ITEM;
|
||||
}
|
||||
|
||||
system->RedirectToLastDir();
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
system->RedirectToLastDir();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rm::MakeGet()
|
||||
void Rm::RemoveDirContent()
|
||||
{
|
||||
if( request->IsParam(L"confirm") )
|
||||
return; // show confirmation dialog
|
||||
if( !request->IsParam(L"r") )
|
||||
{
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
content_dir_iq.WhereParentId(request->dir_tab.back()->id);
|
||||
db->GetItems(item_tab, content_dir_iq);
|
||||
|
||||
for(size_t i=0 ; i<item_tab.size() ; ++i)
|
||||
{
|
||||
if( item_tab[i].type == Item::dir )
|
||||
RemoveDir(item_tab[i]);
|
||||
else
|
||||
RemoveFileOrSymlink(item_tab[i]);
|
||||
}
|
||||
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
system->RedirectToLastDir();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rm::RemoveDir()
|
||||
{
|
||||
if( !request->IsParam(L"r") || request->dir_tab.size() <= 1 )
|
||||
{
|
||||
// we cannot remove the root directory (dir_tab.size()==1)
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveDir(*request->dir_tab.back());
|
||||
request->dir_tab.erase(--request->dir_tab.end());
|
||||
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
system->RedirectToLastDir();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Rm::Clear()
|
||||
{
|
||||
static_item_tab.clear();
|
||||
item_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Rm::MakePost()
|
||||
{
|
||||
Prepare();
|
||||
|
||||
if( request->is_item )
|
||||
{
|
||||
RemoveFile();
|
||||
}
|
||||
else
|
||||
RemoveDir();
|
||||
{
|
||||
if( request->IsPostVar(L"onlycontent") )
|
||||
RemoveDirContent();
|
||||
else
|
||||
RemoveDir();
|
||||
}
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user