diff --git a/packages/flutter_tools/lib/src/base/error_handling_file_system.dart b/packages/flutter_tools/lib/src/base/error_handling_file_system.dart index c039adc5ed..2b29c74fbb 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_file_system.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_file_system.dart @@ -194,6 +194,17 @@ class ErrorHandlingFile ); } + @override + RandomAccessFile openSync({FileMode mode = FileMode.read}) { + return _runSync( + () => delegate.openSync( + mode: mode, + ), + platform: _platform, + failureMessage: 'Flutter failed to open a file at "${delegate.path}"', + ); + } + @override String toString() => delegate.toString(); } @@ -385,9 +396,17 @@ void _handleWindowsException(FileSystemException e, String message) { // https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes const int kDeviceFull = 112; const int kUserMappedSectionOpened = 1224; + const int kAccessDenied = 5; final int errorCode = e.osError?.errorCode ?? 0; // Catch errors and bail when: switch (errorCode) { + case kAccessDenied: + throwToolExit( + '$message. The flutter tool cannot access the file.\n' + 'Please ensure that the SDK and/or project is installed in a location ' + 'that has read/write permissions for the current user.' + ); + break; case kDeviceFull: throwToolExit( '$message. The target device is full.' diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index e81d3d496d..ab9d31c1a1 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -32,18 +32,19 @@ import '../runner/flutter_command.dart'; import '../template.dart'; const List _kAvailablePlatforms = [ - 'ios', - 'android', - 'windows', - 'linux', - 'macos', - 'web', - ]; + 'ios', + 'android', + 'windows', + 'linux', + 'macos', + 'web', +]; const String _kNoPlatformsErrorMessage = ''' The plugin project was generated without specifying the `--platforms` flag, no new platforms are added. To add platforms, run `flutter create -t plugin --platforms .` under the same -directory. You can also find detailed instructions on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms. +directory. You can also find detailed instructions on how to add platforms in the `pubspec.yaml` +at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms. '''; class CreateCommand extends FlutterCommand { @@ -790,7 +791,10 @@ https://flutter.dev/docs/development/packages-and-plugins/developing-packages#pl final Template template = await Template.fromName( templateName, fileSystem: globals.fs, + logger: globals.logger, + templateRenderer: globals.templateRenderer, templateManifest: templateManifest, + pub: pub, ); return template.render(directory, context, overwriteExisting: overwrite); } diff --git a/packages/flutter_tools/lib/src/commands/ide_config.dart b/packages/flutter_tools/lib/src/commands/ide_config.dart index af891d6011..a5844fe50d 100644 --- a/packages/flutter_tools/lib/src/commands/ide_config.dart +++ b/packages/flutter_tools/lib/src/commands/ide_config.dart @@ -254,6 +254,8 @@ class IdeConfigCommand extends FlutterCommand { null, fileSystem: globals.fs, templateManifest: null, + logger: globals.logger, + templateRenderer: globals.templateRenderer, ); return template.render( globals.fs.directory(dirPath), diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index fad3e5cff8..c91dfa6e88 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -15,6 +15,7 @@ import 'base/file_system.dart'; import 'base/logger.dart'; import 'build_info.dart'; import 'bundle.dart' as bundle; +import 'dart/pub.dart'; import 'features.dart'; import 'flutter_manifest.dart'; import 'globals.dart' as globals; @@ -657,7 +658,14 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { } Future _overwriteFromTemplate(String path, Directory target) async { - final Template template = await Template.fromName(path, fileSystem: globals.fs, templateManifest: null); + final Template template = await Template.fromName( + path, + fileSystem: globals.fs, + templateManifest: null, + logger: globals.logger, + templateRenderer: globals.templateRenderer, + pub: pub, + ); template.render( target, { @@ -810,7 +818,14 @@ to migrate your project. } Future _overwriteFromTemplate(String path, Directory target) async { - final Template template = await Template.fromName(path, fileSystem: globals.fs, templateManifest: null); + final Template template = await Template.fromName( + path, + fileSystem: globals.fs, + templateManifest: null, + logger: globals.logger, + templateRenderer: globals.templateRenderer, + pub: pub, + ); template.render( target, { diff --git a/packages/flutter_tools/lib/src/template.dart b/packages/flutter_tools/lib/src/template.dart index 54d87fb898..094321b417 100644 --- a/packages/flutter_tools/lib/src/template.dart +++ b/packages/flutter_tools/lib/src/template.dart @@ -8,10 +8,11 @@ import 'package:package_config/package_config_types.dart'; import 'base/common.dart'; import 'base/file_system.dart'; +import 'base/logger.dart'; +import 'base/template.dart'; import 'cache.dart'; import 'dart/package_map.dart'; import 'dart/pub.dart'; -import 'globals.dart' as globals hide fs; /// Expands templates in a directory to a destination. All files that must /// undergo template expansion should end with the '.tmpl' extension. All files @@ -32,8 +33,12 @@ import 'globals.dart' as globals hide fs; class Template { Template(Directory templateSource, Directory baseDir, this.imageSourceDir, { @required FileSystem fileSystem, + @required Logger logger, + @required TemplateRenderer templateRenderer, @required Set templateManifest, }) : _fileSystem = fileSystem, + _logger = logger, + _templateRenderer = templateRenderer, _templateManifest = templateManifest { _templateFilePaths = {}; @@ -42,14 +47,9 @@ class Template { } final List templateFiles = templateSource.listSync(recursive: true); - - for (final FileSystemEntity entity in templateFiles) { - if (entity is! File) { - // We are only interesting in template *file* URIs. - continue; - } + for (final FileSystemEntity entity in templateFiles.whereType()) { if (_templateManifest != null && !_templateManifest.contains(Uri.file(entity.absolute.path))) { - globals.logger.printTrace('Skipping ${entity.absolute.path}, missing from the template manifest.'); + _logger.printTrace('Skipping ${entity.absolute.path}, missing from the template manifest.'); // Skip stale files in the flutter_tools directory. continue; } @@ -68,20 +68,28 @@ class Template { static Future