copyPackage method

Future copyPackage(
  1. Uri srcUri,
  2. Uri dstUri
)

Implementation

Future copyPackage(Uri srcUri, Uri dstUri) async {
  final dstDir = Directory.fromUri(dstUri);
  if (!dstDir.existsSync()) {
    dstDir.createSync(recursive: true);
  }
  try {
    await copyPath(
      srcUri.toFilePath(windows: Platform.isWindows),
      dstUri.toFilePath(windows: Platform.isWindows),
    );
  } on FileSystemException catch (e) {
    if (Platform.isWindows) {
      final File f = File(e.path!);
      if (f.existsSync()) {
        f.deleteSync();
      }
      File(e.path!).writeAsStringSync('dummy');
      await copyPath(
        srcUri.toFilePath(windows: Platform.isWindows),
        dstUri.toFilePath(windows: Platform.isWindows),
      );
    } else {
      rethrow;
    }
  }

  return context.getFile(srcUri.resolve("pubspec.yaml")).copy(
        dstUri
            .resolve("pubspec.yaml")
            .toFilePath(windows: Platform.isWindows),
      );
}