moveVirtualToVirtual static method

Entity moveVirtualToVirtual(
  1. {required String filePathIn,
  2. required String dirPathOut,
  3. required Virtual fsIn,
  4. required Virtual fsOut,
  5. EntityType type = EntityType.file}
)

Implementation

static Entity moveVirtualToVirtual({
  required String filePathIn,
  required String dirPathOut,
  required Virtual fsIn,
  required Virtual fsOut,
  EntityType type = EntityType.file,
}) {
  final entity = fsIn.open(filePathIn, type: type)!;
  final dirOut = fsOut.open(dirPathOut, type: EntityType.dir)! as VDir;
  final dirIn = fsOut.open(
    dirname(filePathIn),
    type: EntityType.dir,
  )! as VDir;

  if (dirOut.children[entity.name] == null) {
    dirOut.children[entity.name] = entity;
    dirIn.children.remove(entity.name);
  } else {
    throw "[Virtual FileSystem]: file or dir with also name exists!";
  }

  final path = join(dirPathOut, entity.name);
  return switch (type) {
    EntityType.dir => Dir(path),
    EntityType.file => File(path),
  };
}