From e94ccc86f803ab2e4aad8f67b8d32d97894019de Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 20 Apr 2009 21:10:31 +0000 Subject: [PATCH] fixed: a small problem in mountparser (it coused core dumped when there was a wrong mount point supplied) fixed: 'default' funtion can take a directory now (there was an error early) git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@497 e52654a7-88a9-db11-a3e9-0013d4bc506e --- content/content.h | 1 + content/default.cpp | 74 ++++++++++++++++++++++++++++++-------------- core/mountparser.cpp | 2 +- core/mounts.cpp | 2 +- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/content/content.h b/content/content.h index 0920ba3..0354643 100755 --- a/content/content.h +++ b/content/content.h @@ -70,6 +70,7 @@ class Content void PostFunEmacsEdit(bool with_url); void PostFunEmacs(); void PostFunMkdir(bool add_to_dir_table = false); + long PostFunDefaultParsePath(); void PostFunDefault(); void PostFunPriv(); void PostFunCreateThread(); diff --git a/content/default.cpp b/content/default.cpp index f7efa5b..1d89acc 100755 --- a/content/default.cpp +++ b/content/default.cpp @@ -13,12 +13,56 @@ +long Content::PostFunDefaultParsePath() +{ +Item * pdir, * pdir2; +long defaultid = -1; + + std::string & path = request.PostVar("defaultitem"); + + + if( !path.empty() ) + { + std::string dir, file; + Dirs::SplitPath(path, dir, file); + + pdir = data.dirs.GetDir(dir); + + if( !pdir ) + throw Error(Error::incorrect_dir); + + if( file.empty() ) + { + defaultid = pdir->id; + } + else + { + // checking whether the file is a directory too (the method SplitPath does not check it) + pdir2 = data.dirs.GetDir(file, pdir->id); + + if( !pdir2 ) + { + defaultid = db.GetFileId(pdir->id, file); + + if( defaultid == -1 ) + throw Error(Error::db_no_item); + } + else + { + // file is a directory + defaultid = pdir2->id; + } + } + } + +return defaultid; +} + + + void Content::PostFunDefault() { -Item * pdir; -long fileid = -1; - request.session->done = Done::defaulted_dir; @@ -27,31 +71,15 @@ long fileid = -1; request.status = Error::permision_denied; return; } + try { - std::string & path = request.PostVar("defaultitem"); - - if( !path.empty() ) - { - std::string dir, file; - Dirs::SplitPath(path, dir, file); - - pdir = data.dirs.GetDir(dir); - - if( !pdir ) - throw Error(Error::incorrect_dir); - - fileid = db.GetFileId(pdir->id, file); - - if( fileid == -1 ) - throw Error(Error::db_no_item); - } - - request.session->done_status = db.EditDefaultItem(request.dir_table.back()->id, fileid); + long defaultid = PostFunDefaultParsePath(); + request.session->done_status = db.EditDefaultItem(request.dir_table.back()->id, defaultid); if( request.session->done_status == Error::ok ) - request.dir_table.back()->default_item = fileid; + request.dir_table.back()->default_item = defaultid; } catch(const Error & e) { diff --git a/core/mountparser.cpp b/core/mountparser.cpp index b9e3c54..b277570 100755 --- a/core/mountparser.cpp +++ b/core/mountparser.cpp @@ -92,7 +92,7 @@ void MountParser::ReadMountPoint() } else { - err == Error::no_mountpoint; + err = Error::no_mountpoint; log << log1 << "MP: there is no such a mount point: " << temp << logend; } } diff --git a/core/mounts.cpp b/core/mounts.cpp index f4f295e..dca009d 100755 --- a/core/mounts.cpp +++ b/core/mounts.cpp @@ -16,7 +16,7 @@ void Mounts::ReadMounts() MountParser mp; // !! tymczasowo - bedzie odczyt z bazy z /etc/fstab - std::string temp = "thread /forum"; + std::string temp = "thread /news"; Error err = mp.Parse(temp, mount_table);