Scheduler/Console: Make '..' work in Console (closes: #14754)
g0dil [Thu, 27 Nov 2008 09:35:27 +0000 (09:35 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@984 270642c3-0616-0410-b53a-bc976706d245

Scheduler/Console/Executor.cc
Scheduler/Console/Executor.test.cc

index 8f054c7..d6218d8 100644 (file)
@@ -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);
index 2c33677..705622e 100644 (file)
@@ -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");
 }