| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The type of an entity on the file system, such as a file, directory, or link. | 8 * The type of an entity on the file system, such as a file, directory, or link. |
| 9 * | 9 * |
| 10 * These constants are used by the [FileSystemEntity] class | 10 * These constants are used by the [FileSystemEntity] class |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 * Returns a Future which completes with a [FileStat] object containing | 117 * Returns a Future which completes with a [FileStat] object containing |
| 118 * the data returned by stat(). | 118 * the data returned by stat(). |
| 119 * If the call fails, completes the future with a [FileStat] object with | 119 * If the call fails, completes the future with a [FileStat] object with |
| 120 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. | 120 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. |
| 121 */ | 121 */ |
| 122 static Future<FileStat> stat(String path) { | 122 static Future<FileStat> stat(String path) { |
| 123 // Trailing path is not supported on Windows. | 123 // Trailing path is not supported on Windows. |
| 124 if (Platform.isWindows) { | 124 if (Platform.isWindows) { |
| 125 path = FileSystemEntity._trimTrailingPathSeparators(path); | 125 path = FileSystemEntity._trimTrailingPathSeparators(path); |
| 126 } | 126 } |
| 127 return _IOService.dispatch(_FILE_STAT, [path]).then((response) { | 127 return _IOService._dispatch(_FILE_STAT, [path]).then((response) { |
| 128 if (_isErrorResponse(response)) { | 128 if (_isErrorResponse(response)) { |
| 129 return FileStat._notFound; | 129 return FileStat._notFound; |
| 130 } | 130 } |
| 131 // Unwrap the real list from the "I'm not an error" wrapper. | 131 // Unwrap the real list from the "I'm not an error" wrapper. |
| 132 List data = response[1]; | 132 List data = response[1]; |
| 133 return new FileStat._internal( | 133 return new FileStat._internal( |
| 134 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]), | 134 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]), |
| 135 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]), | 135 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]), |
| 136 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]), | 136 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]), |
| 137 FileSystemEntityType._lookup(data[_TYPE]), | 137 FileSystemEntityType._lookup(data[_TYPE]), |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); | 288 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); |
| 289 * if (path == '') path = '.'; | 289 * if (path == '') path = '.'; |
| 290 * new File(path).resolveSymbolicLinks().then((resolved) { | 290 * new File(path).resolveSymbolicLinks().then((resolved) { |
| 291 * print(resolved); | 291 * print(resolved); |
| 292 * }); | 292 * }); |
| 293 * | 293 * |
| 294 * since `Uri.resolve` removes `..` segments. This will result in the Windows | 294 * since `Uri.resolve` removes `..` segments. This will result in the Windows |
| 295 * behavior. | 295 * behavior. |
| 296 */ | 296 */ |
| 297 Future<String> resolveSymbolicLinks() { | 297 Future<String> resolveSymbolicLinks() { |
| 298 return _IOService.dispatch(_FILE_RESOLVE_SYMBOLIC_LINKS, [path]) | 298 return _IOService._dispatch(_FILE_RESOLVE_SYMBOLIC_LINKS, [path]) |
| 299 .then((response) { | 299 .then((response) { |
| 300 if (_isErrorResponse(response)) { | 300 if (_isErrorResponse(response)) { |
| 301 throw _exceptionFromResponse(response, | 301 throw _exceptionFromResponse(response, |
| 302 "Cannot resolve symbolic links", | 302 "Cannot resolve symbolic links", |
| 303 path); | 303 path); |
| 304 } | 304 } |
| 305 return response; | 305 return response; |
| 306 }); | 306 }); |
| 307 } | 307 } |
| 308 | 308 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 * | 452 * |
| 453 * Comparing a link to its target returns false, as does comparing two links | 453 * Comparing a link to its target returns false, as does comparing two links |
| 454 * that point to the same target. To check the target of a link, use | 454 * that point to the same target. To check the target of a link, use |
| 455 * Link.target explicitly to fetch it. Directory links appearing | 455 * Link.target explicitly to fetch it. Directory links appearing |
| 456 * inside a path are followed, though, to find the file system object. | 456 * inside a path are followed, though, to find the file system object. |
| 457 * | 457 * |
| 458 * Completes the returned Future with an error if one of the paths points | 458 * Completes the returned Future with an error if one of the paths points |
| 459 * to an object that does not exist. | 459 * to an object that does not exist. |
| 460 */ | 460 */ |
| 461 static Future<bool> identical(String path1, String path2) { | 461 static Future<bool> identical(String path1, String path2) { |
| 462 return _IOService.dispatch(_FILE_IDENTICAL, [path1, path2]).then((response)
{ | 462 return _IOService._dispatch(_FILE_IDENTICAL, [path1, path2]).then((response)
{ |
| 463 if (_isErrorResponse(response)) { | 463 if (_isErrorResponse(response)) { |
| 464 throw _exceptionFromResponse(response, | 464 throw _exceptionFromResponse(response, |
| 465 "Error in FileSystemEntity.identical($path1, $path2)", ""); | 465 "Error in FileSystemEntity.identical($path1, $path2)", ""); |
| 466 } | 466 } |
| 467 return response; | 467 return response; |
| 468 }); | 468 }); |
| 469 } | 469 } |
| 470 | 470 |
| 471 static final RegExp _absoluteWindowsPathPattern = | 471 static final RegExp _absoluteWindowsPathPattern = |
| 472 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); | 472 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 */ | 650 */ |
| 651 Directory get parent => new Directory(parentOf(path)); | 651 Directory get parent => new Directory(parentOf(path)); |
| 652 | 652 |
| 653 static int _getTypeSync(String path, bool followLinks) { | 653 static int _getTypeSync(String path, bool followLinks) { |
| 654 var result = _getType(path, followLinks); | 654 var result = _getType(path, followLinks); |
| 655 _throwIfError(result, 'Error getting type of FileSystemEntity'); | 655 _throwIfError(result, 'Error getting type of FileSystemEntity'); |
| 656 return result; | 656 return result; |
| 657 } | 657 } |
| 658 | 658 |
| 659 static Future<int> _getTypeAsync(String path, bool followLinks) { | 659 static Future<int> _getTypeAsync(String path, bool followLinks) { |
| 660 return _IOService.dispatch(_FILE_TYPE, [path, followLinks]) | 660 return _IOService._dispatch(_FILE_TYPE, [path, followLinks]) |
| 661 .then((response) { | 661 .then((response) { |
| 662 if (_isErrorResponse(response)) { | 662 if (_isErrorResponse(response)) { |
| 663 throw _exceptionFromResponse(response, "Error getting type", path); | 663 throw _exceptionFromResponse(response, "Error getting type", path); |
| 664 } | 664 } |
| 665 return response; | 665 return response; |
| 666 }); | 666 }); |
| 667 } | 667 } |
| 668 | 668 |
| 669 static _throwIfError(Object result, String msg, [String path]) { | 669 static _throwIfError(Object result, String msg, [String path]) { |
| 670 if (result is OSError) { | 670 if (result is OSError) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 return buffer.toString(); | 824 return buffer.toString(); |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 | 827 |
| 828 | 828 |
| 829 class _FileSystemWatcher { | 829 class _FileSystemWatcher { |
| 830 external static Stream<FileSystemEvent> watch( | 830 external static Stream<FileSystemEvent> watch( |
| 831 String path, int events, bool recursive); | 831 String path, int events, bool recursive); |
| 832 external static bool get isSupported; | 832 external static bool get isSupported; |
| 833 } | 833 } |
| OLD | NEW |