| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 this.mode, this.size); | 82 this.mode, this.size); |
| 83 | 83 |
| 84 const FileStat._internalNotFound() | 84 const FileStat._internalNotFound() |
| 85 : changed = null, | 85 : changed = null, |
| 86 modified = null, | 86 modified = null, |
| 87 accessed = null, | 87 accessed = null, |
| 88 type = FileSystemEntityType.NOT_FOUND, | 88 type = FileSystemEntityType.NOT_FOUND, |
| 89 mode = 0, | 89 mode = 0, |
| 90 size = -1; | 90 size = -1; |
| 91 | 91 |
| 92 external static _statSync(String path); | 92 external static _statSync(_Namespace namespace, String path); |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Calls the operating system's stat() function on [path]. | 95 * Calls the operating system's stat() function on [path]. |
| 96 * Returns a [FileStat] object containing the data returned by stat(). | 96 * Returns a [FileStat] object containing the data returned by stat(). |
| 97 * If the call fails, returns a [FileStat] object with .type set to | 97 * If the call fails, returns a [FileStat] object with .type set to |
| 98 * FileSystemEntityType.NOT_FOUND and the other fields invalid. | 98 * FileSystemEntityType.NOT_FOUND and the other fields invalid. |
| 99 */ | 99 */ |
| 100 static FileStat statSync(String path) { | 100 static FileStat statSync(String path) { |
| 101 // Trailing path is not supported on Windows. | 101 // Trailing path is not supported on Windows. |
| 102 if (Platform.isWindows) { | 102 if (Platform.isWindows) { |
| 103 path = FileSystemEntity._trimTrailingPathSeparators(path); | 103 path = FileSystemEntity._trimTrailingPathSeparators(path); |
| 104 } | 104 } |
| 105 var data = _statSync(path); | 105 var data = _statSync(_Namespace._namespace, path); |
| 106 if (data is OSError) return FileStat._notFound; | 106 if (data is OSError) return FileStat._notFound; |
| 107 return new FileStat._internal( | 107 return new FileStat._internal( |
| 108 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]), | 108 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]), |
| 109 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]), | 109 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]), |
| 110 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]), | 110 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]), |
| 111 FileSystemEntityType._lookup(data[_TYPE]), | 111 FileSystemEntityType._lookup(data[_TYPE]), |
| 112 data[_MODE], | 112 data[_MODE], |
| 113 data[_SIZE]); | 113 data[_SIZE]); |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Asynchronously calls the operating system's stat() function on [path]. | 117 * Asynchronously calls the operating system's stat() function on [path]. |
| 118 * Returns a Future which completes with a [FileStat] object containing | 118 * Returns a Future which completes with a [FileStat] object containing |
| 119 * the data returned by stat(). | 119 * the data returned by stat(). |
| 120 * If the call fails, completes the future with a [FileStat] object with | 120 * If the call fails, completes the future with a [FileStat] object with |
| 121 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. | 121 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. |
| 122 */ | 122 */ |
| 123 static Future<FileStat> stat(String path) { | 123 static Future<FileStat> stat(String path) { |
| 124 // Trailing path is not supported on Windows. | 124 // Trailing path is not supported on Windows. |
| 125 if (Platform.isWindows) { | 125 if (Platform.isWindows) { |
| 126 path = FileSystemEntity._trimTrailingPathSeparators(path); | 126 path = FileSystemEntity._trimTrailingPathSeparators(path); |
| 127 } | 127 } |
| 128 return _IOService._dispatch(_FILE_STAT, [path]).then((response) { | 128 return _File |
| 129 ._dispatchWithNamespace(_FILE_STAT, [null, path]).then((response) { |
| 129 if (_isErrorResponse(response)) { | 130 if (_isErrorResponse(response)) { |
| 130 return FileStat._notFound; | 131 return FileStat._notFound; |
| 131 } | 132 } |
| 132 // Unwrap the real list from the "I'm not an error" wrapper. | 133 // Unwrap the real list from the "I'm not an error" wrapper. |
| 133 List data = response[1]; | 134 List data = response[1]; |
| 134 return new FileStat._internal( | 135 return new FileStat._internal( |
| 135 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]), | 136 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]), |
| 136 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]), | 137 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]), |
| 137 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]), | 138 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]), |
| 138 FileSystemEntityType._lookup(data[_TYPE]), | 139 FileSystemEntityType._lookup(data[_TYPE]), |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); | 297 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); |
| 297 * if (path == '') path = '.'; | 298 * if (path == '') path = '.'; |
| 298 * new File(path).resolveSymbolicLinks().then((resolved) { | 299 * new File(path).resolveSymbolicLinks().then((resolved) { |
| 299 * print(resolved); | 300 * print(resolved); |
| 300 * }); | 301 * }); |
| 301 * | 302 * |
| 302 * since `Uri.resolve` removes `..` segments. This will result in the Windows | 303 * since `Uri.resolve` removes `..` segments. This will result in the Windows |
| 303 * behavior. | 304 * behavior. |
| 304 */ | 305 */ |
| 305 Future<String> resolveSymbolicLinks() { | 306 Future<String> resolveSymbolicLinks() { |
| 306 return _IOService | 307 return _File._dispatchWithNamespace( |
| 307 ._dispatch(_FILE_RESOLVE_SYMBOLIC_LINKS, [path]).then((response) { | 308 _FILE_RESOLVE_SYMBOLIC_LINKS, [null, path]).then((response) { |
| 308 if (_isErrorResponse(response)) { | 309 if (_isErrorResponse(response)) { |
| 309 throw _exceptionFromResponse( | 310 throw _exceptionFromResponse( |
| 310 response, "Cannot resolve symbolic links", path); | 311 response, "Cannot resolve symbolic links", path); |
| 311 } | 312 } |
| 312 return response; | 313 return response; |
| 313 }); | 314 }); |
| 314 } | 315 } |
| 315 | 316 |
| 316 /** | 317 /** |
| 317 * Resolves the path of a file system object relative to the | 318 * Resolves the path of a file system object relative to the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 334 * | 335 * |
| 335 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); | 336 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); |
| 336 * if (path == '') path = '.'; | 337 * if (path == '') path = '.'; |
| 337 * var resolved = new File(path).resolveSymbolicLinksSync(); | 338 * var resolved = new File(path).resolveSymbolicLinksSync(); |
| 338 * print(resolved); | 339 * print(resolved); |
| 339 * | 340 * |
| 340 * since `Uri.resolve` removes `..` segments. This will result in the Windows | 341 * since `Uri.resolve` removes `..` segments. This will result in the Windows |
| 341 * behavior. | 342 * behavior. |
| 342 */ | 343 */ |
| 343 String resolveSymbolicLinksSync() { | 344 String resolveSymbolicLinksSync() { |
| 344 var result = _resolveSymbolicLinks(path); | 345 var result = _resolveSymbolicLinks(_Namespace._namespace, path); |
| 345 _throwIfError(result, "Cannot resolve symbolic links", path); | 346 _throwIfError(result, "Cannot resolve symbolic links", path); |
| 346 return result; | 347 return result; |
| 347 } | 348 } |
| 348 | 349 |
| 349 /** | 350 /** |
| 350 * Calls the operating system's stat() function on the [path] of this | 351 * Calls the operating system's stat() function on the [path] of this |
| 351 * [FileSystemEntity]. Identical to [:FileStat.stat(this.path):]. | 352 * [FileSystemEntity]. Identical to [:FileStat.stat(this.path):]. |
| 352 * | 353 * |
| 353 * Returns a [:Future<FileStat>:] object containing the data returned by | 354 * Returns a [:Future<FileStat>:] object containing the data returned by |
| 354 * stat(). | 355 * stat(). |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 * | 456 * |
| 456 * Comparing a link to its target returns false, as does comparing two links | 457 * Comparing a link to its target returns false, as does comparing two links |
| 457 * that point to the same target. To check the target of a link, use | 458 * that point to the same target. To check the target of a link, use |
| 458 * Link.target explicitly to fetch it. Directory links appearing | 459 * Link.target explicitly to fetch it. Directory links appearing |
| 459 * inside a path are followed, though, to find the file system object. | 460 * inside a path are followed, though, to find the file system object. |
| 460 * | 461 * |
| 461 * Completes the returned Future with an error if one of the paths points | 462 * Completes the returned Future with an error if one of the paths points |
| 462 * to an object that does not exist. | 463 * to an object that does not exist. |
| 463 */ | 464 */ |
| 464 static Future<bool> identical(String path1, String path2) { | 465 static Future<bool> identical(String path1, String path2) { |
| 465 return _IOService | 466 return _File._dispatchWithNamespace( |
| 466 ._dispatch(_FILE_IDENTICAL, [path1, path2]).then((response) { | 467 _FILE_IDENTICAL, [null, path1, path2]).then((response) { |
| 467 if (_isErrorResponse(response)) { | 468 if (_isErrorResponse(response)) { |
| 468 throw _exceptionFromResponse(response, | 469 throw _exceptionFromResponse(response, |
| 469 "Error in FileSystemEntity.identical($path1, $path2)", ""); | 470 "Error in FileSystemEntity.identical($path1, $path2)", ""); |
| 470 } | 471 } |
| 471 return response; | 472 return response; |
| 472 }); | 473 }); |
| 473 } | 474 } |
| 474 | 475 |
| 475 static final RegExp _absoluteWindowsPathPattern = | 476 static final RegExp _absoluteWindowsPathPattern = |
| 476 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); | 477 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 * | 518 * |
| 518 * Comparing a link to its target returns false, as does comparing two links | 519 * Comparing a link to its target returns false, as does comparing two links |
| 519 * that point to the same target. To check the target of a link, use | 520 * that point to the same target. To check the target of a link, use |
| 520 * Link.target explicitly to fetch it. Directory links appearing | 521 * Link.target explicitly to fetch it. Directory links appearing |
| 521 * inside a path are followed, though, to find the file system object. | 522 * inside a path are followed, though, to find the file system object. |
| 522 * | 523 * |
| 523 * Throws an error if one of the paths points to an object that does not | 524 * Throws an error if one of the paths points to an object that does not |
| 524 * exist. | 525 * exist. |
| 525 */ | 526 */ |
| 526 static bool identicalSync(String path1, String path2) { | 527 static bool identicalSync(String path1, String path2) { |
| 527 var result = _identical(path1, path2); | 528 var result = _identical(_Namespace._namespace, path1, path2); |
| 528 _throwIfError(result, 'Error in FileSystemEntity.identicalSync'); | 529 _throwIfError(result, 'Error in FileSystemEntity.identicalSync'); |
| 529 return result; | 530 return result; |
| 530 } | 531 } |
| 531 | 532 |
| 532 /** | 533 /** |
| 533 * Test if [watch] is supported on the current system. | 534 * Test if [watch] is supported on the current system. |
| 534 * | 535 * |
| 535 * OS X 10.6 and below is not supported. | 536 * OS X 10.6 and below is not supported. |
| 536 */ | 537 */ |
| 537 static bool get isWatchSupported => _FileSystemWatcher.isSupported; | 538 static bool get isWatchSupported => _FileSystemWatcher.isSupported; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 static bool isFileSync(String path) => | 601 static bool isFileSync(String path) => |
| 601 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); | 602 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); |
| 602 | 603 |
| 603 /** | 604 /** |
| 604 * Synchronously checks if typeSync(path) returns | 605 * Synchronously checks if typeSync(path) returns |
| 605 * FileSystemEntityType.DIRECTORY. | 606 * FileSystemEntityType.DIRECTORY. |
| 606 */ | 607 */ |
| 607 static bool isDirectorySync(String path) => | 608 static bool isDirectorySync(String path) => |
| 608 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); | 609 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); |
| 609 | 610 |
| 610 external static _getType(String path, bool followLinks); | 611 external static _getType(_Namespace namespace, String path, bool followLinks); |
| 611 external static _identical(String path1, String path2); | 612 external static _identical(_Namespace namespace, String path1, String path2); |
| 612 external static _resolveSymbolicLinks(String path); | 613 external static _resolveSymbolicLinks(_Namespace namespace, String path); |
| 613 | 614 |
| 614 // Finds the next-to-last component when dividing at path separators. | 615 // Finds the next-to-last component when dividing at path separators. |
| 615 static final RegExp _parentRegExp = Platform.isWindows | 616 static final RegExp _parentRegExp = Platform.isWindows |
| 616 ? new RegExp(r'[^/\\][/\\]+[^/\\]') | 617 ? new RegExp(r'[^/\\][/\\]+[^/\\]') |
| 617 : new RegExp(r'[^/]/+[^/]'); | 618 : new RegExp(r'[^/]/+[^/]'); |
| 618 | 619 |
| 619 /** | 620 /** |
| 620 * Removes the final path component of a path, using the platform's | 621 * Removes the final path component of a path, using the platform's |
| 621 * path separator to split the path. Will not remove the root component | 622 * path separator to split the path. Will not remove the root component |
| 622 * of a Windows path, like "C:\\" or "\\\\server_name\\". | 623 * of a Windows path, like "C:\\" or "\\\\server_name\\". |
| (...skipping 23 matching lines...) Expand all Loading... |
| 646 return '.'; | 647 return '.'; |
| 647 } | 648 } |
| 648 } | 649 } |
| 649 | 650 |
| 650 /** | 651 /** |
| 651 * The directory containing [this]. | 652 * The directory containing [this]. |
| 652 */ | 653 */ |
| 653 Directory get parent => new Directory(parentOf(path)); | 654 Directory get parent => new Directory(parentOf(path)); |
| 654 | 655 |
| 655 static int _getTypeSync(String path, bool followLinks) { | 656 static int _getTypeSync(String path, bool followLinks) { |
| 656 var result = _getType(path, followLinks); | 657 var result = _getType(_Namespace._namespace, path, followLinks); |
| 657 _throwIfError(result, 'Error getting type of FileSystemEntity'); | 658 _throwIfError(result, 'Error getting type of FileSystemEntity'); |
| 658 return result; | 659 return result; |
| 659 } | 660 } |
| 660 | 661 |
| 661 static Future<int> _getTypeAsync(String path, bool followLinks) { | 662 static Future<int> _getTypeAsync(String path, bool followLinks) { |
| 662 return _IOService | 663 return _File._dispatchWithNamespace( |
| 663 ._dispatch(_FILE_TYPE, [path, followLinks]).then((response) { | 664 _FILE_TYPE, [null, path, followLinks]).then((response) { |
| 664 if (_isErrorResponse(response)) { | 665 if (_isErrorResponse(response)) { |
| 665 throw _exceptionFromResponse(response, "Error getting type", path); | 666 throw _exceptionFromResponse(response, "Error getting type", path); |
| 666 } | 667 } |
| 667 return response; | 668 return response; |
| 668 }); | 669 }); |
| 669 } | 670 } |
| 670 | 671 |
| 671 static _throwIfError(Object result, String msg, [String path]) { | 672 static _throwIfError(Object result, String msg, [String path]) { |
| 672 if (result is OSError) { | 673 if (result is OSError) { |
| 673 throw new FileSystemException(msg, path, result); | 674 throw new FileSystemException(msg, path, result); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 buffer.write(')'); | 824 buffer.write(')'); |
| 824 return buffer.toString(); | 825 return buffer.toString(); |
| 825 } | 826 } |
| 826 } | 827 } |
| 827 | 828 |
| 828 class _FileSystemWatcher { | 829 class _FileSystemWatcher { |
| 829 external static Stream<FileSystemEvent> _watch( | 830 external static Stream<FileSystemEvent> _watch( |
| 830 String path, int events, bool recursive); | 831 String path, int events, bool recursive); |
| 831 external static bool get isSupported; | 832 external static bool get isSupported; |
| 832 } | 833 } |
| OLD | NEW |