createEntity method

bool createEntity(
  1. AffogatoVFSEntity entity, {
  2. String? dirId,
})

The method caller is responsible for ensuring that the AffogatoVFSEntity.entityId field of the provided entity does not have any collisions. This method checks to ensure that there are no conflicting names of files/directories in the specified location, dir, before inserting the entity.

Implementation

bool createEntity(AffogatoVFSEntity entity, {String? dirId}) {
  final AffogatoVFSEntity? dir = dirId != null
      ? accessEntity(dirId)
      : api.workspace.workspaceConfigs.vfs.root;
  if (dir == null) return false;

  if ((entity.isDirectory ? dir.subdirs : dir.files)
      .every((item) => item.name != entity.name)) {
    (entity.isDirectory ? dir.subdirs : dir.files).add(entity);
    return true;
  }
  return false;
}