From: g0dil Date: Thu, 27 Nov 2008 09:35:27 +0000 (+0000) Subject: Scheduler/Console: Make '..' work in Console (closes: #14754) X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=97a384b0738fed15b7d90b373408ffed52043c13;p=senf.git Scheduler/Console: Make '..' work in Console (closes: #14754) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@984 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/Console/Executor.cc b/Scheduler/Console/Executor.cc index 8f054c7..d6218d8 100644 --- a/Scheduler/Console/Executor.cc +++ b/Scheduler/Console/Executor.cc @@ -249,8 +249,17 @@ senf::console::Executor::traverseNode(ParseCommandInfo::TokensRange const & path path.begin(), boost::prior(path.end())), dir); + // For auto-cd support we need to check against '.' and '..' here too + Token const & tok (*boost::prior(path.end())); + if (tok == WordToken("..")) { + if (dir.size() > 1) + dir.pop_back(); + return *dir.back().lock(); + } DirectoryNode & base (*dir.back().lock()); - std::string const & name (complete(base, boost::prior(path.end())->value())); + if (tok == WordToken(".")) + return base; + std::string const & name (complete(base, tok.value())); if (policy_) policy_( base, name ); return dir.back().lock()->get(name); diff --git a/Scheduler/Console/Executor.test.cc b/Scheduler/Console/Executor.test.cc index 2c33677..705622e 100644 --- a/Scheduler/Console/Executor.test.cc +++ b/Scheduler/Console/Executor.test.cc @@ -231,7 +231,7 @@ BOOST_AUTO_UNIT_TEST(executorPolicy) BOOST_AUTO_UNIT_TEST(executorAuto) { - senf::console::root().mkdir("dir1").mkdir("dir3"); + senf::console::root().mkdir("tdir1").mkdir("dir3"); senf::console::root().mkdir("dir2").doc("Helptext").add("test",&testCommand); senf::console::Executor executor; @@ -247,6 +247,22 @@ BOOST_AUTO_UNIT_TEST(executorAuto) BOOST_CHECK_EQUAL( executor.cwdPath(), "/dir2" ); BOOST_CHECK_EQUAL( os.str(), "" ); } + + { + std::stringstream os; + parser.parse("..", &setCommand); + executor(os, commands.back()); + BOOST_CHECK_EQUAL( executor.cwdPath(), "/" ); + BOOST_CHECK_EQUAL( os.str(), "" ); + } + + { + std::stringstream os; + parser.parse("d", &setCommand); + executor(os, commands.back()); + BOOST_CHECK_EQUAL( executor.cwdPath(), "/dir2" ); + BOOST_CHECK_EQUAL( os.str(), "" ); + } { std::stringstream os; @@ -257,7 +273,7 @@ BOOST_AUTO_UNIT_TEST(executorAuto) commands.clear(); - senf::console::root().remove("dir1"); + senf::console::root().remove("tdir1"); senf::console::root().remove("dir2"); }