blob: 4b3f3c5f330886820f36ef68df81b81a714bd714 [file] [log] [blame] [view]
# addNode method
*[<Null safety>](https://dart.dev/null-safety)*
int addNode
(String name, [Vnode](../../package-fuchsia_vfs_vfs/Vnode-class.md) node)
<p>Adds a directory entry associating the given <code>name</code> with <code>node</code>.
It is ok to add the same Vnode multiple times with different names.</p>
<p>Returns <code>ZX.OK</code> on success.
Returns <code>ZX.ERR_INVALID_ARGS</code> if name is illegal object name.
Returns <code>ZX.ERR_ALREADY_EXISTS</code> if there is already a node with the
given name.</p>
## Implementation
```dart
int addNode(String name, Vnode node) {
if (!_isLegalObjectName(name)) {
return ZX.ERR_INVALID_ARGS;
}
if (_entries.containsKey(name)) {
return ZX.ERR_ALREADY_EXISTS;
}
final id = _nextId++;
final e = _Entry(node, name, id);
_entries[name] = e;
_treeEntries.add(e);
return ZX.OK;
}
```