renameEntity method

Future<void> renameEntity(
  1. VEntity entity,
  2. String newName
)

Implementation

Future<void> renameEntity(VEntity entity, String newName) async {
  if (entity is VFile) {
    String newPath = VPaths.join(entity.parentPath, newName);
    await onMoveFile(entity, newPath);
    warn("MOVE FILE ${entity.path} -> $newPath");
  } else if (entity is VFolder) {
    String newPath = VPaths.join(entity.parentPath, newName);

    if (await exists(newPath)) {
      throw Exception("Already exists");
    }

    VFolder newFolder = await mkdir(newPath);
    await Future.wait(
        await getChildren(entity).map((i) => move(i, newFolder)).toList());
    await delete(entity);
  }

  update();
}