Google is committed to advancing racial equity for Black communities. See how.

open method

  • @override

void open (int flags, int mode, String path, InterfaceRequest request, [int parentFlags = Flags.fsRights]) override

This function is called from fuchsia.io.Directory#open. This function parses path and opens correct node.

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 ERR_NOT_DIR.

Implementation

@override
void open(
    int flags, int mode, String path, fidl.InterfaceRequest<Node> request,
    [int parentFlags = Flags.fsRights]) {
  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);
  }

  if (p == '.' || p == '') {
    connect(flags, mode, request, parentFlags);
    return;
  }
  var index = p.indexOf('/');
  var key = '';
  if (index == -1) {
    key = p;
  } else {
    key = p.substring(0, index);
  }
  if (!_isLegalObjectName(key)) {
    sendErrorEvent(flags, ZX.ERR_BAD_PATH, request);
  } else if (_entries.containsKey(key)) {
    var 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 | openFlagDirectory, 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);
  }
}