[Windows] Improve symlink ERROR_ACCESS_DENIED error message (#154030)
Currently, if creating a symlink on Windows fails due to `ERROR_ACCESS_DENIED`, you'll get an error message like: ``` Error: ERROR_ACCESS_DENIED file system exception thrown while trying to create a symlink from source to dest ``` The `source` and `dest` paths are incorrect. This will help us debug: https://github.com/flutter/flutter/issues/153758
This commit is contained in:
@@ -993,8 +993,8 @@ void _createPlatformPluginSymlinks(Directory symlinkDirectory, List<Object?>? pl
|
|||||||
e,
|
e,
|
||||||
platform: globals.platform,
|
platform: globals.platform,
|
||||||
os: globals.os,
|
os: globals.os,
|
||||||
destination: 'dest',
|
destination: link.path,
|
||||||
source: 'source',
|
source: path,
|
||||||
);
|
);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1844,24 +1844,73 @@ The Flutter Preview device does not support the following plugins from your pubs
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('Symlink ERROR_ACCESS_DENIED failures show developers paths that were used', () async {
|
testUsingContext('Symlink ERROR_ACCESS_DENIED failures show developers paths that were used', () async {
|
||||||
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
final FakeFlutterProject flutterProject = FakeFlutterProject()
|
||||||
final FakeOperatingSystemUtils os = FakeOperatingSystemUtils('Microsoft Windows [Version 10.0.14972.1]');
|
..directory = globals.fs.currentDirectory.childDirectory('app');
|
||||||
|
final Directory windowsManagedDirectory = flutterProject.directory
|
||||||
|
.childDirectory('windows')
|
||||||
|
.childDirectory('flutter');
|
||||||
|
final FakeWindowsProject windowsProject = FakeWindowsProject()
|
||||||
|
..managedDirectory = windowsManagedDirectory
|
||||||
|
..pluginSymlinkDirectory = windowsManagedDirectory
|
||||||
|
.childDirectory('ephemeral')
|
||||||
|
.childDirectory('.plugin_symlinks')
|
||||||
|
..exists = true;
|
||||||
|
|
||||||
const FileSystemException e = FileSystemException('', '', OSError('', 5));
|
final File dependenciesFile = flutterProject.directory
|
||||||
|
.childFile('.flutter-plugins-dependencies');
|
||||||
|
flutterProject
|
||||||
|
..flutterPluginsDependenciesFile = dependenciesFile
|
||||||
|
..windows = windowsProject;
|
||||||
|
|
||||||
|
flutterProject.directory.childFile('.packages').createSync(recursive: true);
|
||||||
|
|
||||||
|
const String dependenciesFileContents = r'''
|
||||||
|
{
|
||||||
|
"plugins": {
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"name": "some_plugin",
|
||||||
|
"path": "C:\\some_plugin"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
dependenciesFile.writeAsStringSync(dependenciesFileContents);
|
||||||
|
|
||||||
|
const String expectedMessage =
|
||||||
|
'ERROR_ACCESS_DENIED file system exception thrown while trying to '
|
||||||
|
r'create a symlink from C:\some_plugin to '
|
||||||
|
r'C:\app\windows\flutter\ephemeral\.plugin_symlinks\some_plugin';
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
() => handleSymlinkException(
|
() => createPluginSymlinks(
|
||||||
e,
|
flutterProject,
|
||||||
platform: platform,
|
featureFlagsOverride: TestFeatureFlags(isWindowsEnabled: true),
|
||||||
os: os,
|
|
||||||
source: pubCachePath,
|
|
||||||
destination: ephemeralPackagePath,
|
|
||||||
),
|
|
||||||
throwsToolExit(
|
|
||||||
message: 'ERROR_ACCESS_DENIED file system exception thrown while trying to create a symlink from $pubCachePath to $ephemeralPackagePath',
|
|
||||||
),
|
),
|
||||||
|
throwsToolExit(message: expectedMessage),
|
||||||
);
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
FileSystem: () {
|
||||||
|
final FileExceptionHandler handle = FileExceptionHandler();
|
||||||
|
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
|
||||||
|
platform: FakePlatform(),
|
||||||
|
delegate: MemoryFileSystem.test(
|
||||||
|
style: FileSystemStyle.windows,
|
||||||
|
opHandle: handle.opHandle,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const String pluginSymlinkPath = r'C:\app\windows\flutter\ephemeral\.plugin_symlinks\some_plugin';
|
||||||
|
handle.addError(
|
||||||
|
fileSystem.link(pluginSymlinkPath),
|
||||||
|
FileSystemOp.create,
|
||||||
|
const FileSystemException('', '', OSError('', 5)),
|
||||||
|
);
|
||||||
|
return fileSystem;
|
||||||
|
},
|
||||||
|
Platform: () => FakePlatform(operatingSystem: 'windows'),
|
||||||
|
ProcessManager: () => FakeProcessManager.empty(),
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('Symlink failures instruct developers to run as administrator on older versions of Windows', () async {
|
testWithoutContext('Symlink failures instruct developers to run as administrator on older versions of Windows', () async {
|
||||||
|
|||||||
Reference in New Issue
Block a user