| 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 'file_system.dart'; | 10 import 'file_system.dart'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 _PhysicalFileSystemEntity(this.uri); | 36 _PhysicalFileSystemEntity(this.uri); |
| 37 | 37 |
| 38 @override | 38 @override |
| 39 int get hashCode => uri.hashCode; | 39 int get hashCode => uri.hashCode; |
| 40 | 40 |
| 41 @override | 41 @override |
| 42 bool operator ==(Object other) => | 42 bool operator ==(Object other) => |
| 43 other is _PhysicalFileSystemEntity && other.uri == uri; | 43 other is _PhysicalFileSystemEntity && other.uri == uri; |
| 44 | 44 |
| 45 @override | 45 @override |
| 46 Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes(); | |
| 47 | |
| 48 @override | |
| 49 Future<String> readAsString() => new io.File.fromUri(uri).readAsString(); | |
| 50 | |
| 51 @override | |
| 52 Future<bool> exists() async { | 46 Future<bool> exists() async { |
| 53 if (await io.FileSystemEntity.isFile(uri.toFilePath())) { | 47 if (await io.FileSystemEntity.isFile(uri.toFilePath())) { |
| 54 return new io.File.fromUri(uri).exists(); | 48 return new io.File.fromUri(uri).exists(); |
| 55 } else { | 49 } else { |
| 56 return new io.Directory.fromUri(uri).exists(); | 50 return new io.Directory.fromUri(uri).exists(); |
| 57 } | 51 } |
| 58 } | 52 } |
| 59 | 53 |
| 60 @override | 54 @override |
| 61 Future<DateTime> lastModified() => new io.File.fromUri(uri).lastModified(); | 55 Future<DateTime> lastModified() async { |
| 56 try { |
| 57 return await new io.File.fromUri(uri).lastModified(); |
| 58 } on io.FileSystemException catch (exception) { |
| 59 throw _toFileSystemException(exception); |
| 60 } |
| 61 } |
| 62 |
| 63 @override |
| 64 Future<List<int>> readAsBytes() async { |
| 65 try { |
| 66 return await new io.File.fromUri(uri).readAsBytes(); |
| 67 } on io.FileSystemException catch (exception) { |
| 68 throw _toFileSystemException(exception); |
| 69 } |
| 70 } |
| 71 |
| 72 @override |
| 73 Future<String> readAsString() async { |
| 74 try { |
| 75 return await new io.File.fromUri(uri).readAsString(); |
| 76 } on io.FileSystemException catch (exception) { |
| 77 throw _toFileSystemException(exception); |
| 78 } |
| 79 } |
| 80 |
| 81 /** |
| 82 * Return the [FileSystemException] for the given I/O exception. |
| 83 */ |
| 84 FileSystemException _toFileSystemException(io.FileSystemException exception) { |
| 85 String message = exception.message; |
| 86 String osMessage = exception.osError?.message; |
| 87 if (osMessage != null && osMessage.isNotEmpty) { |
| 88 message = osMessage; |
| 89 } |
| 90 return new FileSystemException(uri, message); |
| 91 } |
| 62 } | 92 } |
| OLD | NEW |