| |
| |
| |
| # open method |
| |
| |
| |
| |
| *[<Null safety>](https://dart.dev/null-safety)* |
| |
| |
| |
| - @override |
| |
| void open |
| (dynamic flags, int mode, String path, [InterfaceRequest](../../package-fidl_fidl/InterfaceRequest-class.md) request, [dynamic parentFlags]) |
| |
| _<span class="feature">override</span>_ |
| |
| |
| |
| <p>This function is called from <code>fidl_fuchsia_io.Directory#open</code>. |
| This function parses path and opens correct node.</p> |
| <p>Vnode provides a simplified implementation for non-directory types. |
| Behavior: |
| For directory types, it will throw UnimplementedError error. |
| For non empty path it will fail with <code>ERR_NOT_DIR</code>.</p> |
| |
| |
| |
| ## Implementation |
| |
| ```dart |
| @override |
| void open(OpenFlags flags, int mode, String path, |
| fidl.InterfaceRequest<Node> request, |
| [OpenFlags? parentFlags]) { |
| if (path.startsWith('/') || path == '') { |
| sendErrorEvent(flags, ZX.ERR_BAD_PATH, request); |
| return; |
| } |
| var p = path; |
| // remove all ./, .//, etc |
| while (p.startsWith('./')) { |
| var index = 2; |
| while (index < p.length && p[index] == '/') { |
| index++; |
| } |
| p = p.substring(index); |
| } |
| |
| parentFlags ??= Flags.fsRightsDefault(); |
| if (p == '.' || p == '') { |
| connect(flags, mode, request, parentFlags); |
| return; |
| } |
| final index = p.indexOf('/'); |
| final key = index == -1 ? p : p.substring(0, index); |
| if (!_isLegalObjectName(key)) { |
| sendErrorEvent(flags, ZX.ERR_BAD_PATH, request); |
| } else if (_entries.containsKey(key)) { |
| final e = _entries[key]; |
| // final element, open it |
| if (index == -1) { |
| e!.node!.connect(flags, mode, request, parentFlags); |
| return; |
| } else if (index == p.length - 1) { |
| // '/' is at end, should be a directory, add flag |
| e!.node! |
| .connect(flags | OpenFlags.directory, mode, request, parentFlags); |
| return; |
| } else { |
| // forward request to child Vnode and let it handle rest of path. |
| return e!.node! |
| .open(flags, mode, p.substring(index + 1), request, parentFlags); |
| } |
| } else { |
| sendErrorEvent(flags, ZX.ERR_NOT_FOUND, request); |
| } |
| } |
| ``` |
| |
| |
| |
| |
| |
| |
| |