From 86d6c96aeb431c325e1f0862011f06de8c73a710 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 3 Jun 2012 02:14:33 +0000 Subject: [PATCH] fixed: winix_subdomain ezc function didn't print the subdomain added: to rm winix function: bool Rm::RemoveItemByPath(const std::wstring & path, bool check_access) fixed: in Upload winix function when uploading an image we have to get a mount point where the image is placed (parent dir) (it was cur->mount beforehand) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@844 e52654a7-88a9-db11-a3e9-0013d4bc506e --- functions/rm.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- functions/rm.h | 11 ++++++++++- functions/upload.cpp | 36 ++++++++++++++++-------------------- templates/winix.cpp | 2 +- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/functions/rm.cpp b/functions/rm.cpp index 3be11aa..9db81d1 100755 --- a/functions/rm.cpp +++ b/functions/rm.cpp @@ -216,8 +216,10 @@ return RemoveFile(item); // for other uses (plugins etc) -void Rm::RemoveItemById(long item_id, bool check_access) +bool Rm::RemoveItemById(long item_id, bool check_access) { +bool result = false; + // selecting files, symlinks and directories rm_by_id_iq.SetAll(false, false); rm_by_id_iq.sel_parent_id = true; @@ -233,14 +235,49 @@ void Rm::RemoveItemById(long item_id, bool check_access) if( db->GetItem(rm_by_id_item, rm_by_id_iq) == WINIX_ERR_OK ) { if( rm_by_id_item.type == Item::dir ) + { RemoveDirTree(rm_by_id_item, true, check_access); + result = true; // RemoveDirTree doesn't return a status + } else - RemoveFileOrSymlink(rm_by_id_item, check_access); + { + result = RemoveFileOrSymlink(rm_by_id_item, check_access); + } } + +return result; } +bool Rm::RemoveItemByPath(const std::wstring & path, bool check_access) +{ +bool result = false; + + int res = system->FollowAllLinks(path, rm_path_dir_tab, rm_path_item); + + if( res == 0 ) + { + Item * dir = system->dirs.GetDir(rm_path_dir_tab.back()->id); + + if( dir ) + { + RemoveDirTree(*dir, true, check_access); + result = false; + } + } + else + if( res == 1 ) + { + result = RemoveFileOrSymlink(rm_path_item, check_access); + } + +return result; +} + + + + bool Rm::RemoveDirFiles(long dir_id, bool check_access) { content_dir_iq.WhereParentId(dir_id); diff --git a/functions/rm.h b/functions/rm.h index 8c0e745..f6abbf6 100755 --- a/functions/rm.h +++ b/functions/rm.h @@ -35,7 +35,13 @@ public: // removing either a directory or a symlink or a file // if item_id is a directory then the whole subdirectories are removed too - void RemoveItemById(long item_id, bool check_access = true); + bool RemoveItemById(long item_id, bool check_access = true); + + // removing either a directory or a symlink or a file + // if path is a directory then the whole subdirectories are removed too + // path must begin with a slash (or can be empty then the root directory is removed) + bool RemoveItemByPath(const std::wstring & path, bool check_access = true); + private: @@ -51,6 +57,9 @@ private: DbItemQuery rm_by_id_iq; Item rm_by_id_item; + std::vector rm_path_dir_tab; + Item rm_path_item; + bool HasAccessToDir(const Item & dir, bool only_content); void Prepare(); void Clear(); diff --git a/functions/upload.cpp b/functions/upload.cpp index 9c0beb0..fbeaa82 100755 --- a/functions/upload.cpp +++ b/functions/upload.cpp @@ -35,10 +35,6 @@ bool Upload::HasAccess(const Item & item) // you can use 'upload' only in a directory if( item.type != Item::dir ) return false; - - // we must know where to store the file - if( !system->mounts.pmount ) - return false; if( config->upload_dir.empty() ) { @@ -93,7 +89,7 @@ bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_fi void Upload::ResizeImage(Item & item) { - ::Mount & m = *cur->mount; + ::Mount * m = system->mounts.CalcMount(item.parent_id); size_t cx = config->image_cx; size_t cy = config->image_cy; int mode = config->image_mode; @@ -102,23 +98,23 @@ void Upload::ResizeImage(Item & item) // reading width and height from the mount point (if exists) int index = system->mounts.MountParImageSize(); - if( m.param[index].defined && m.param[index].arg.size() == 2 ) + if( m && m->param[index].defined && m->param[index].arg.size() == 2 ) { - cx = Tol(m.param[index].arg[0]); - cy = Tol(m.param[index].arg[1]); + cx = Tol(m->param[index].arg[0]); + cy = Tol(m->param[index].arg[1]); } // reading image mode from the mount point (if exists) index = system->mounts.MountParImageMode(); - if( m.param[index].defined && m.param[index].arg.size() == 1 ) - mode = Toi(m.param[index].arg[0]); + if( m && m->param[index].defined && m->param[index].arg.size() == 1 ) + mode = Toi(m->param[index].arg[0]); // reading image quality from the mount point (if exists) index = system->mounts.MountParImageQuality(); - if( m.param[index].defined && m.param[index].arg.size() == 1 ) - quality = Toi(m.param[index].arg[0]); + if( m && m->param[index].defined && m->param[index].arg.size() == 1 ) + quality = Toi(m->param[index].arg[0]); system->image.Resize(item, cx, cy, mode, quality); } @@ -127,7 +123,7 @@ void Upload::ResizeImage(Item & item) void Upload::CreateThumb(Item & item) { - ::Mount & m = *cur->mount; + ::Mount * m = system->mounts.CalcMount(item.parent_id); size_t cx = config->thumb_cx; size_t cy = config->thumb_cy; int mode = config->thumb_mode; @@ -136,23 +132,23 @@ void Upload::CreateThumb(Item & item) // reading width and height from the mount point (if exists) int index = system->mounts.MountParThumbSize(); - if( m.param[index].defined && m.param[index].arg.size() == 2 ) + if( m && m->param[index].defined && m->param[index].arg.size() == 2 ) { - cx = Tol(m.param[index].arg[0]); - cy = Tol(m.param[index].arg[1]); + cx = Tol(m->param[index].arg[0]); + cy = Tol(m->param[index].arg[1]); } // reading thumb mode from the mount point (if exists) index = system->mounts.MountParThumbMode(); - if( m.param[index].defined && m.param[index].arg.size() == 1 ) - mode = Toi(m.param[index].arg[0]); + if( m && m->param[index].defined && m->param[index].arg.size() == 1 ) + mode = Toi(m->param[index].arg[0]); // reading image quality from the mount point (if exists) index = system->mounts.MountParThumbQuality(); - if( m.param[index].defined && m.param[index].arg.size() == 1 ) - quality = Toi(m.param[index].arg[0]); + if( m && m->param[index].defined && m->param[index].arg.size() == 1 ) + quality = Toi(m->param[index].arg[0]); system->image.CreateThumb(item, cx, cy, mode, quality); } diff --git a/templates/winix.cpp b/templates/winix.cpp index 93cf034..9506609 100755 --- a/templates/winix.cpp +++ b/templates/winix.cpp @@ -284,7 +284,7 @@ void winix_postvar_value_is_not(Info & i) void winix_subdomain(Info & i) { - cur->request->subdomain; + i.out << cur->request->subdomain; }