allows method

  1. @override
bool allows(
  1. dynamic operation
)
override

Checks if this permission allows the given operation.

Implementation

@override
bool allows(dynamic operation) {
  if (operation is! Map<String, dynamic>) return false;

  final opType = operation['type'];
  final opPath = operation['path'];

  if (opType != 'filesystem') return false;

  // Check if the operation is allowed
  final requiredRead = operation['read'] ?? false;
  final requiredWrite = operation['write'] ?? false;
  final requiredExecute = operation['execute'] ?? false;

  if ((requiredRead && !_read) ||
      (requiredWrite && !_write) ||
      (requiredExecute && !_execute)) {
    return false;
  }

  // Check path restrictions. An unscoped grant (`_path == null`) means "any
  // path" and skips this entirely.
  if (_path != null) {
    // Some operations have no meaningful path — the `dart:io` import gate,
    // for instance, asks only "is ANY filesystem access granted?". Those opt
    // out of the scope check explicitly; note this waives the PATH check
    // only, never the read/write/execute flags checked above.
    if (operation['pathAgnostic'] == true) {
      return true;
    }
    // No path and not path-agnostic: the matcher cannot prove the operation
    // is in scope, so it denies rather than assuming.
    if (opPath is! String || !_isPathWithinScope(_path, opPath)) {
      return false;
    }
  }

  return true;
}