accessEntity<T> method
AffogatoVFSEntity?
accessEntity<T>(})
This gets ahold of an entity in the VFS, so that actions can be performed on it.
If the type of the entity is known in advance, then passing isDir accordingly will
help filter results faster.
The stepCallback, if specified, will be called on each item that is accessed during the recursive
search process, and the supplied AffogatoVFSEntity argument will be the current item of the search. This
is useful for performing side actions during search, such as collecing the paths of parent entities.
However, this method stops once the target entity is found. To exhaustively iterate over all subdirs and files,
use traverseBFS instead.
Implementation
AffogatoVFSEntity? accessEntity<T>(
String id, {
bool? isDir,
void Function(AffogatoVFSEntity)? stepCallback,
void Function(AffogatoVFSEntity?)? action,
}) {
// only use the cache if the caller has not provided any callbacks to be executed
if (stepCallback == null &&
action == null &&
api.workspace.workspaceConfigs.vfs.cache.containsKey(id)) {
return api.workspace.workspaceConfigs.vfs.cache[id]!;
}
final res = api.workspace.workspaceConfigs.vfs.root.findById(
id,
isDir: isDir,
stepCallback: stepCallback,
action: action,
);
if (res != null) {
return api.workspace.workspaceConfigs.vfs.cache[id] = res;
} else {
return null;
}
}