private static void doUnwrapSingleTopLevelFolder(@NotNull Path unzipToDir, @NotNull Path targetDir) throws IOException {
    List<Path> topLevelFiles;
    try (Stream<Path> stream = Files.list(unzipToDir)) {
      topLevelFiles = stream.collect(Collectors.toList());
    }
    catch (NoSuchFileException e) {
      return;
    }

    Path dirToMove;
    List<Path> children;
    if (topLevelFiles.size() == 1 && Files.isDirectory(topLevelFiles.get(0))) {
      dirToMove = topLevelFiles.get(0);
      try (Stream<Path> stream = Files.list(dirToMove)) {
        children = stream.collect(Collectors.toList());
      }
    }
    else {
      dirToMove = unzipToDir;
      children = topLevelFiles;
    }

    // don't "FileUtil.moveDirWithContent(dirToMove, targetDir)"
    // because a file moved with "java.io.File.renameTo" won't inherit its new parent's permissions
    for (Path child : children) {
      Path to = targetDir.resolve(dirToMove.relativize(child));
      if (Files.isDirectory(child)) {
        FileUtil.copyDir(child.toFile(), to.toFile(), true);
      }
      else {
        Files.createDirectories(to.getParent());
        Files.copy(child, to, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
      }
    }
    FileUtil.delete(unzipToDir);
  }
private static void doUnwrapSingleTopLevelFolder(@NotNull Path unzipToDir, @NotNull Path targetDir)