Skip to content

[flutter_tools] Extract Windows archives using native tar with PowerShell fallback - #192298

Merged
auto-submit[bot] merged 8 commits into
flutter:masterfrom
bkonyi:optimize-windows-archive-extraction
Sep 17, 2026
Merged

auto-submit[bot] merged 8 commits into
flutter:masterfrom
bkonyi:optimize-windows-archive-extraction

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

Today, flutter_tools extracts archives on Windows using package:archive in memory because historically Windows lacked a built-in unzipping CLI tool. This causes high memory consumption, slow extraction speeds, and out-of-memory crashes on large archives (#133371). Furthermore, package:archive 4.x introduced a dependency on package:posix which relies on native FFI and cannot execute on Windows (#115660).

This PR:

  1. Updates _WindowsUtils.unzip and _WindowsUtils.unpack in os.dart to use native %WINDIR%\System32\tar.exe (available on Windows 10 build 17063+ / version 1803 and Windows 11). This streams extraction directly from disk to disk, eliminating OOM crashes and providing significantly faster throughput.
  2. Adds a backwards-compatible fallback to PowerShell Expand-Archive (checking powershell then pwsh) with verbatim single-quote escaping and $ErrorActionPreference = "Stop" for older Windows 10 versions.
  3. Automatically creates missing destination directories prior to extraction.
  4. Decouples WindowsApp.fromPrebuiltApp in application_package.dart from package:archive by handling general Exception.
  5. Removes package:archive from os.dart and os_test.dart.
  6. Adds unit tests covering Windows tar unzipping, target directory creation, PowerShell fallback, PowerShell Core (pwsh) fallback, and tool-missing error exits.

Related Issues

Tests

  • Added unit tests in packages/flutter_tools/test/general.shard/base/os_test.dart
  • Added unit tests in packages/flutter_tools/test/general.shard/windows/application_package_test.dart
  • Verified with flutter test and clean dart analyze --fatal-infos

bkonyi added 2 commits August 22, 2026 23:27
…d test manual pins

Decouples WindowsApp.fromPrebuiltApp from package:archive by catching
general Exception rather than ArchiveException when unzipping prebuilt
archives, eliminating an unused dependency import.

Adds regression and invariant tests in update_packages_test to verify
that package:archive is explicitly pinned to 3.6.1 in
kManuallyPinnedDependencies to prevent unwanted transitive dependencies
(package:posix).

Fixes flutter#115660
…hell fallback

Replaces in-memory extraction via package:archive in _WindowsUtils with
native tar (available on Windows 10 build 17063+) and PowerShell
Expand-Archive fallback (powershell / pwsh) for backwards compatibility.

This eliminates out-of-memory crashes on Windows when extracting large
archives and removes all package:archive dependencies from
packages/flutter_tools/lib/src/base/os.dart.

Fixes flutter#133371
Part of flutter#115660
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Sep 4, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Sep 4, 2026
Reverts changes to update_packages_test.dart which added test assertions
for package:archive in kManuallyPinnedDependencies and macro packages,
keeping the PR focused strictly on the Windows archive extraction
optimization.
@bkonyi
bkonyi marked this pull request as ready for review September 4, 2026 19:58
@bkonyi
bkonyi requested a review from a team as a code owner September 4, 2026 19:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the dependency on the archive package in flutter_tools on Windows, replacing it with native system tools like tar and PowerShell's Expand-Archive. Feedback on these changes includes ensuring that ToolExit is not swallowed when catching exceptions during unzipping in application_package.dart (which requires importing ../base/common.dart), and using single quotes for 'Stop' in the PowerShell script to avoid escaping issues.

- Rethrow ToolExit when unzipping in application_package to avoid masking
  missing extraction tools as invalid archives.
- Add test verifying ToolExit rethrow in application_package_test.
- Use single quotes for 'Stop' in PowerShell error action preference script.

@mattkae mattkae left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One piece of feedback, but largely looks good by me!

…ion on Windows

Moves the targetDirectory.createSync check to the top of unzip in
_WindowsUtils to avoid duplicating the check across extraction paths.
@bkonyi
bkonyi requested a review from mattkae September 10, 2026 16:17
@mattkae mattkae added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2026
@auto-submit

auto-submit Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/192298, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@mattkae mattkae added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 17, 2026
Merged via the queue into flutter:master with commit b138043 Sep 17, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tools] Optimize archive extraction on Windows

2 participants