| 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; |
| 11 |
| 10 import 'file_system.dart'; | 12 import 'file_system.dart'; |
| 11 | 13 |
| 12 /// Concrete implementation of [FileSystem] which performs its operations using | 14 /// Concrete implementation of [FileSystem] which performs its operations using |
| 13 /// I/O. | 15 /// I/O. |
| 14 /// | 16 /// |
| 15 /// Not intended to be implemented or extended by clients. | 17 /// Not intended to be implemented or extended by clients. |
| 16 class PhysicalFileSystem implements FileSystem { | 18 class PhysicalFileSystem implements FileSystem { |
| 17 static final PhysicalFileSystem instance = new PhysicalFileSystem._(); | 19 static final PhysicalFileSystem instance = new PhysicalFileSystem._(); |
| 18 | 20 |
| 19 PhysicalFileSystem._(); | 21 PhysicalFileSystem._(); |
| 20 | 22 |
| 21 @override | 23 @override |
| 24 p.Context get context => p.context; |
| 25 |
| 26 @override |
| 22 FileSystemEntity entityForUri(Uri uri) { | 27 FileSystemEntity entityForUri(Uri uri) { |
| 23 if (uri.scheme != 'file' && uri.scheme != '') { | 28 if (uri.scheme != 'file' && uri.scheme != '') { |
| 24 throw new ArgumentError('File URI expected'); | 29 throw new ArgumentError('File URI expected'); |
| 25 } | 30 } |
| 26 return new _PhysicalFileSystemEntity(Uri.base.resolveUri(uri)); | 31 return new _PhysicalFileSystemEntity(Uri.base.resolveUri(uri)); |
| 27 } | 32 } |
| 28 } | 33 } |
| 29 | 34 |
| 30 /// Concrete implementation of [FileSystemEntity] for use by | 35 /// Concrete implementation of [FileSystemEntity] for use by |
| 31 /// [PhysicalFileSystem]. | 36 /// [PhysicalFileSystem]. |
| 32 class _PhysicalFileSystemEntity implements FileSystemEntity { | 37 class _PhysicalFileSystemEntity implements FileSystemEntity { |
| 33 @override | 38 @override |
| 34 final Uri uri; | 39 final Uri uri; |
| 35 | 40 |
| 36 _PhysicalFileSystemEntity(this.uri); | 41 _PhysicalFileSystemEntity(this.uri); |
| 37 | 42 |
| 38 @override | 43 @override |
| 39 int get hashCode => uri.hashCode; | 44 int get hashCode => uri.hashCode; |
| 40 | 45 |
| 41 @override | 46 @override |
| 42 bool operator ==(Object other) => | 47 bool operator ==(Object other) => |
| 43 other is _PhysicalFileSystemEntity && other.uri == uri; | 48 other is _PhysicalFileSystemEntity && other.uri == uri; |
| 44 | 49 |
| 45 @override | 50 @override |
| 46 Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes(); | 51 Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes(); |
| 47 | 52 |
| 48 @override | 53 @override |
| 49 Future<String> readAsString() => new io.File.fromUri(uri).readAsString(); | 54 Future<String> readAsString() => new io.File.fromUri(uri).readAsString(); |
| 50 | |
| 51 @override | |
| 52 Future<bool> exists() async { | |
| 53 if (await io.FileSystemEntity.isFile(uri.toFilePath())) { | |
| 54 return new io.File.fromUri(uri).exists(); | |
| 55 } else { | |
| 56 return new io.Directory.fromUri(uri).exists(); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 @override | |
| 61 Future<DateTime> lastModified() => new io.File.fromUri(uri).lastModified(); | |
| 62 } | 55 } |
| OLD | NEW |