Skip to content

Commit d98c9f5

Browse files
andrewkolosGitHub Actions Bot
authored and
GitHub Actions Bot
committed
Use ErrorHandlingFileSystem.deleteIfExists when deleting .plugin_symlinks (flutter#151073)
Fixes flutter#137168.
1 parent 754bbba commit d98c9f5

File tree

4 files changed

+75
-6
lines changed

4 files changed

+75
-6
lines changed

packages/flutter_tools/lib/src/base/error_handling_io.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
9595
}
9696
if (entity.existsSync()) {
9797
throwToolExit(
98-
'The Flutter tool tried to delete the file or directory ${entity.path} but was '
99-
"unable to. This may be due to the file and/or project's location on a read-only "
100-
'volume. Consider relocating the project and trying again',
98+
'Unable to delete file or directory at "${entity.path}". '
99+
'This may be due to the project being in a read-only '
100+
'volume. Consider relocating the project and trying again.',
101101
);
102102
}
103103
}

packages/flutter_tools/lib/src/flutter_plugins.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,9 @@ void handleSymlinkException(FileSystemException e, {
962962
///
963963
/// If [force] is true, the directory will be created only if missing.
964964
void _createPlatformPluginSymlinks(Directory symlinkDirectory, List<Object?>? platformPlugins, {bool force = false}) {
965-
if (force && symlinkDirectory.existsSync()) {
965+
if (force) {
966966
// Start fresh to avoid stale links.
967-
symlinkDirectory.deleteSync(recursive: true);
967+
ErrorHandlingFileSystem.deleteIfExists(symlinkDirectory, recursive: true);
968968
}
969969
symlinkDirectory.createSync(recursive: true);
970970
if (platformPlugins == null) {

packages/flutter_tools/test/general.shard/cache_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void main() {
871871
handler.addError(webCacheDirectory, FileSystemOp.delete, const FileSystemException('', '', OSError('', 2)));
872872

873873
await expectLater(() => webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils()), throwsToolExit(
874-
message: RegExp('The Flutter tool tried to delete the file or directory cache/bin/cache/flutter_web_sdk but was unable to'),
874+
message: RegExp('Unable to delete file or directory at "cache/bin/cache/flutter_web_sdk"'),
875875
));
876876
});
877877

packages/flutter_tools/test/general.shard/plugins_test.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// found in the LICENSE file.
44

55
import 'dart:convert';
6+
import 'dart:io';
67

78
import 'package:file/file.dart';
89
import 'package:file/memory.dart';
910
import 'package:file_testing/file_testing.dart';
11+
import 'package:flutter_tools/src/base/error_handling_io.dart';
1012
import 'package:flutter_tools/src/base/os.dart';
1113
import 'package:flutter_tools/src/base/platform.dart';
1214
import 'package:flutter_tools/src/base/time.dart';
@@ -1482,6 +1484,73 @@ The Flutter Preview device does not support the following plugins from your pubs
14821484
);
14831485
});
14841486
});
1487+
1488+
testUsingContext('exits tool when deleting .plugin_symlinks fails', () async {
1489+
final FakeFlutterProject flutterProject = FakeFlutterProject()
1490+
..directory = globals.fs.currentDirectory.childDirectory('app');
1491+
final FakeFlutterManifest flutterManifest = FakeFlutterManifest();
1492+
final Directory windowsManagedDirectory = flutterProject.directory
1493+
.childDirectory('windows')
1494+
.childDirectory('flutter');
1495+
final FakeWindowsProject windowsProject = FakeWindowsProject()
1496+
..managedDirectory = windowsManagedDirectory
1497+
..cmakeFile = windowsManagedDirectory.parent.childFile('CMakeLists.txt')
1498+
..generatedPluginCmakeFile =
1499+
windowsManagedDirectory.childFile('generated_plugins.mk')
1500+
..pluginSymlinkDirectory = windowsManagedDirectory
1501+
.childDirectory('ephemeral')
1502+
.childDirectory('.plugin_symlinks')
1503+
..exists = true;
1504+
1505+
flutterProject
1506+
..manifest = flutterManifest
1507+
..flutterPluginsFile =
1508+
flutterProject.directory.childFile('.flutter-plugins')
1509+
..flutterPluginsDependenciesFile =
1510+
flutterProject.directory.childFile('.flutter-plugins-dependencies')
1511+
..windows = windowsProject;
1512+
1513+
flutterProject.directory.childFile('.packages').createSync(recursive: true);
1514+
1515+
createPluginSymlinks(
1516+
flutterProject,
1517+
force: true,
1518+
featureFlagsOverride: TestFeatureFlags(isWindowsEnabled: true),
1519+
);
1520+
1521+
expect(
1522+
() => createPluginSymlinks(
1523+
flutterProject,
1524+
force: true,
1525+
featureFlagsOverride: TestFeatureFlags(isWindowsEnabled: true),
1526+
),
1527+
throwsToolExit(
1528+
message: RegExp('Unable to delete file or directory at '
1529+
r'"C:\\app\\windows\\flutter\\ephemeral\\\.plugin_symlinks"')),
1530+
);
1531+
}, overrides: <Type, Generator>{
1532+
FileSystem: () {
1533+
final FileExceptionHandler handle = FileExceptionHandler();
1534+
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
1535+
platform: FakePlatform(),
1536+
delegate: MemoryFileSystem.test(
1537+
style: FileSystemStyle.windows,
1538+
opHandle: handle.opHandle,
1539+
),
1540+
);
1541+
const String symlinkDirectoryPath = r'C:\app\windows\flutter\ephemeral\.plugin_symlinks';
1542+
handle.addError(
1543+
fileSystem.directory(symlinkDirectoryPath),
1544+
FileSystemOp.delete,
1545+
const PathNotFoundException(
1546+
symlinkDirectoryPath,
1547+
OSError('The system cannot find the path specified.', 3),
1548+
),
1549+
);
1550+
return fileSystem;
1551+
},
1552+
ProcessManager: () => FakeProcessManager.empty(),
1553+
});
14851554
}
14861555

14871556
class FakeFlutterManifest extends Fake implements FlutterManifest {

0 commit comments

Comments
 (0)