moveEntity method

bool moveEntity({
  1. required String entityId,
  2. required String newDirId,
})

A similar implementation to deleteEntity, except that the entity cache is not updated and the directory specified by newDirId gets updated to contain the entity specified by entityId.

Implementation

bool moveEntity({
  required String entityId,
  required String newDirId,
}) {
  AffogatoVFSEntity? parentDir;
  final AffogatoVFSEntity? result = accessEntity(
    entityId,
    stepCallback: (currentItem) {
      if (parentDir == null &&
          currentItem.isDirectory &&
          currentItem.entityId != entityId) {
        parentDir = currentItem;
      }
    },
  );
  final AffogatoVFSEntity? target = accessEntity(newDirId, isDir: true);
  if (result == null || target == null) return false;

  if (!result.isDirectory) {
    parentDir!.files.remove(result);
    target.files.add(result);
  } else {
    parentDir!.subdirs.remove(result);
    target.subdirs.add(result);
  }

  return true;
}