Skip to content

Commit f960c3a

Browse files
authored
[flutter_tools] Stop deletion progress status during flutter clean (#192996)
Ensure `deletionStatus.stop()` is always called in a `finally` block around `file.deleteSync(recursive: true)` in `CleanCommand._deleteFile`. Previously, `deletionStatus.stop()` was only called inside the `on FileSystemException catch` block, leaving `StdoutLogger._status` active on successful file deletions. Because `StdoutLogger.startProgress` ignores new statuses when `_status != null` and only emits the trailing newline in `stop()` / `cancel()`, the first `Deleting ...` progress status remained unstopped, suppressing all subsequent deletion progress statuses and omitting the trailing newline on exit. Adds a regression test in `packages/flutter_tools/test/commands.shard/hermetic/clean_test.dart` verifying that `flutter clean` stops each deletion progress status and logs every deleted directory. Fixes #192531 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 12384f9 commit f960c3a

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎packages/flutter_tools/lib/src/commands/clean.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ class CleanCommand extends FlutterCommand {
209209
try {
210210
file.deleteSync(recursive: true);
211211
} on FileSystemException catch (error) {
212-
deletionStatus.stop();
213212
final String path = file.path;
214213
if (_toolContext.platform.isWindows) {
215214
if (await _tryStopGradleAndRetryDelete(file, project)) {
@@ -227,6 +226,8 @@ class CleanCommand extends FlutterCommand {
227226
} else {
228227
logger.printError('Failed to remove $path: $error');
229228
}
229+
} finally {
230+
deletionStatus.stop();
230231
}
231232
}
232233

‎packages/flutter_tools/test/commands.shard/hermetic/clean_test.dart‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,34 @@ void main() {
133133
expect(xcodeProjectInterpreter.workspaces, isEmpty);
134134
});
135135

136+
testWithoutContext(
137+
'$CleanCommand stops progress status for each deleted directory',
138+
() async {
139+
setupProjectUnderTest(fs.currentDirectory, false);
140+
final stdio = FakeStdio();
141+
final stdoutLogger = StdoutLogger(
142+
terminal: AnsiTerminal(stdio: stdio, platform: FakePlatform()),
143+
stdio: stdio,
144+
outputPreferences: OutputPreferences.test(),
145+
);
146+
final CommandRunner<void> runner = createTestCommandRunner(
147+
createCleanCommand(
148+
fs: fs,
149+
logger: stdoutLogger,
150+
xcode: xcode,
151+
xcodeProjectInterpreter: xcodeProjectInterpreter,
152+
),
153+
);
154+
await runner.run(<String>['clean']);
155+
156+
final String output = stdio.writtenToStdout.join();
157+
expect(output, contains('Deleting build...'));
158+
expect(output, contains('Deleting .dart_tool...'));
159+
expect(output, contains('Deleting ephemeral...'));
160+
expect(output.endsWith('\n'), isTrue);
161+
},
162+
);
163+
136164
testWithoutContext('$CleanCommand does not clean the example directory by default', () async {
137165
setupProjectUnderTest(fs.currentDirectory, true);
138166
final FlutterProject exampleProject = setupProjectUnderTest(

0 commit comments

Comments
 (0)