Skip to content

extract method produce invalid code with continue #62069

@stephane-archer

Description

@stephane-archer
Future<void> _addDirectoryToZip({
  required ZipEncoder encoder,
  required Directory dir,
  required String zipEntryPath,
  required Set<String> ancestors,
}) async {
  final canonical = await dir.resolveSymbolicLinks();

  if (ancestors.contains(canonical)) {
    return;
  }

  final newAncestors = {...ancestors, canonical};

  await for (final fsEntity in dir.list(recursive: false, followLinks: false)) {
    final name = path_lib.basename(fsEntity.path);
    final entryPath =
        zipEntryPath.isEmpty ? name : path_lib.join(zipEntryPath, name);

    var real = fsEntity;

    if (fsEntity is Link) {
      final resolved = await fsEntity.resolveSymbolicLinks();
      final type = FileSystemEntity.typeSync(resolved);

      if (type == FileSystemEntityType.file) {
        real = File(resolved);
      } else if (type == FileSystemEntityType.directory) {
        if (newAncestors.contains(resolved)) {
          final dirFile = ArchiveFile.directory(entryPath);
          encoder.add(dirFile);
          continue; /// extract any method with this continue inside, and the produced code would be invalid
        }
        real = Directory(resolved);
      } else {
        throw FileSystemException('Broken symlink', fsEntity.path);
      }
    }

    if (real is Directory) {
      final dirFile = ArchiveFile.directory(entryPath);
      encoder.add(dirFile);

      await _addDirectoryToZip(
        encoder: encoder,
        dir: real,
        zipEntryPath: entryPath,
        ancestors: newAncestors,
      );
    }

    if (real is File) {
      final input = InputFileStream(real.path);

      final archiveFile = ArchiveFile.stream(
        entryPath,
        input,
      );

      archiveFile.lastModTime =
          real.lastModifiedSync().millisecondsSinceEpoch ~/ 1000;

      archiveFile.compression = CompressionType.none;

      encoder.add(archiveFile);

      await input.close();
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions