Pers_dir(const char *name, mode_t mode)
: Node(name, (mode & 0777) | __S_IFDIR) {}
Ref_ptr<Node> find_path(cxx::String);
- int add_node(Ref_ptr<Node> const &);
+ bool add_node(Ref_ptr<Node> const &);
typedef Tree::Const_iterator Const_iterator;
Const_iterator begin() const { return _tree.begin(); }
return cxx::ref_ptr(_tree.find_node(path));
}
-int Pers_dir::add_node(Ref_ptr<Node> const &n)
+bool Pers_dir::add_node(Ref_ptr<Node> const &n)
{
- int e = _tree.insert(n.ptr()).second;
- if (!e)
+ bool e = _tree.insert(n.ptr()).second;
+ if (e)
n->add_ref();
return e;
}
{
Ref_ptr<Node> node(new Pers_file(n.start(), mode));
// when ENOENT is return, path is always a directory
- int e = cxx::ref_ptr_static_cast<Pers_dir>(path)->add_node(node);
- if (e)
- return e;
+ bool e = cxx::ref_ptr_static_cast<Pers_dir>(path)->add_node(node);
+ if (!e)
+ return -ENOMEM;
path = node;
}
Ref_ptr<Pers_dir> dnode = cxx::ref_ptr_static_cast<Pers_dir>(node);
Ref_ptr<Pers_dir> dir(new Pers_dir(last.start(), mode));
- return dnode->add_node(dir);
+ return dnode->add_node(dir) ? 0 : -EEXIST;
}
int