allow moving up a node with cd
Change-Id: Id1419fddda4aa2d2c16b5775a43c8df58db98c73
diff --git a/src/CTree.cpp b/src/CTree.cpp
index 5d0cf7e..69afb58 100644
--- a/src/CTree.cpp
+++ b/src/CTree.cpp
@@ -13,6 +13,10 @@
InvalidNodeException::~InvalidNodeException() = default;
struct nodeToString : public boost::static_visitor<std::string> {
+ std::string operator()(const nodeup_&) const
+ {
+ return "..";
+ }
template <class T>
std::string operator()(const T& node) const
{
@@ -94,7 +98,6 @@
m_nodes.emplace(name, std::unordered_map<std::string, NodeType>());
}
-
void CTree::changeNode(const path_& name)
{
if (name.m_nodes.empty()) {
@@ -102,7 +105,13 @@
return;
}
for (const auto& it : name.m_nodes) {
- m_curDir = joinPaths(m_curDir, boost::apply_visitor(nodeToString(), it));
+ const std::string node = boost::apply_visitor(nodeToString(), it);
+ if (node == "..") {
+ m_curDir = stripLastNodeFromPath(m_curDir);
+ } else {
+ m_curDir = joinPaths(m_curDir, boost::apply_visitor(nodeToString(), it));
+ }
+
}
}
std::string CTree::currentNode() const