| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library front_end.physical_file_system; | 5 library front_end.physical_file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 11 | 11 |
| 12 import 'file_system.dart'; | 12 import 'file_system.dart'; |
| 13 | 13 |
| 14 /// Concrete implementation of [FileSystem] which performs its operations using | 14 /// Concrete implementation of [FileSystem] which performs its operations using |
| 15 /// I/O. | 15 /// I/O. |
| 16 /// | 16 /// |
| 17 /// Not intended to be implemented or extended by clients. | 17 /// Not intended to be implemented or extended by clients. |
| 18 class PhysicalFileSystem implements FileSystem { | 18 class PhysicalFileSystem implements FileSystem { |
| 19 static final PhysicalFileSystem instance = new PhysicalFileSystem._(); | 19 static final PhysicalFileSystem instance = new PhysicalFileSystem._(); |
| 20 | 20 |
| 21 PhysicalFileSystem._(); | 21 PhysicalFileSystem._(); |
| 22 | 22 |
| 23 @override | 23 @override |
| 24 p.Context get context => p.context; | 24 p.Context get context => p.context; |
| 25 | 25 |
| 26 @override | 26 @override |
| 27 FileSystemEntity entityForPath(String path) => | |
| 28 new _PhysicalFileSystemEntity(context.normalize(context.absolute(path))); | |
| 29 | |
| 30 @override | |
| 31 FileSystemEntity entityForUri(Uri uri) { | 27 FileSystemEntity entityForUri(Uri uri) { |
| 32 if (uri.scheme != 'file') throw new ArgumentError('File URI expected'); | 28 if (uri.scheme != 'file' && uri.scheme != '') { |
| 29 throw new ArgumentError('File URI expected'); |
| 30 } |
| 33 // Note: we don't have to verify that the URI's path is absolute, because | 31 // Note: we don't have to verify that the URI's path is absolute, because |
| 34 // URIs with non-empty schemes always have absolute paths. | 32 // URIs with non-empty schemes always have absolute paths. |
| 35 return entityForPath(context.fromUri(uri)); | 33 var path = context.fromUri(uri); |
| 34 return new _PhysicalFileSystemEntity( |
| 35 context.normalize(context.absolute(path))); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 /// Concrete implementation of [FileSystemEntity] for use by | 39 /// Concrete implementation of [FileSystemEntity] for use by |
| 40 /// [PhysicalFileSystem]. | 40 /// [PhysicalFileSystem]. |
| 41 class _PhysicalFileSystemEntity implements FileSystemEntity { | 41 class _PhysicalFileSystemEntity implements FileSystemEntity { |
| 42 @override | 42 final String _path; |
| 43 final String path; | |
| 44 | 43 |
| 45 _PhysicalFileSystemEntity(this.path); | 44 _PhysicalFileSystemEntity(this._path); |
| 46 | 45 |
| 47 @override | 46 @override |
| 48 int get hashCode => path.hashCode; | 47 int get hashCode => _path.hashCode; |
| 48 |
| 49 @override |
| 50 Uri get uri => p.toUri(_path); |
| 49 | 51 |
| 50 @override | 52 @override |
| 51 bool operator ==(Object other) => | 53 bool operator ==(Object other) => |
| 52 other is _PhysicalFileSystemEntity && other.path == path; | 54 other is _PhysicalFileSystemEntity && other._path == _path; |
| 53 | 55 |
| 54 @override | 56 @override |
| 55 Future<List<int>> readAsBytes() => new io.File(path).readAsBytes(); | 57 Future<List<int>> readAsBytes() => new io.File(_path).readAsBytes(); |
| 56 | 58 |
| 57 @override | 59 @override |
| 58 Future<String> readAsString() => new io.File(path).readAsString(); | 60 Future<String> readAsString() => new io.File(_path).readAsString(); |
| 59 } | 61 } |
| OLD | NEW |