Chromium Code Reviews| 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 class FileSystemEntityType { | 7 class FileSystemEntityType { |
| 8 static const FILE = const FileSystemEntityType._internal(0); | 8 static const FILE = const FileSystemEntityType._internal(0); |
| 9 static const DIRECTORY = const FileSystemEntityType._internal(1); | 9 static const DIRECTORY = const FileSystemEntityType._internal(1); |
| 10 static const LINK = const FileSystemEntityType._internal(2); | 10 static const LINK = const FileSystemEntityType._internal(2); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 * Synchronously checks if typeSync(path) returns | 523 * Synchronously checks if typeSync(path) returns |
| 524 * FileSystemEntityType.DIRECTORY. | 524 * FileSystemEntityType.DIRECTORY. |
| 525 */ | 525 */ |
| 526 static bool isDirectorySync(String path) => | 526 static bool isDirectorySync(String path) => |
| 527 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); | 527 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); |
| 528 | 528 |
| 529 external static _getType(String path, bool followLinks); | 529 external static _getType(String path, bool followLinks); |
| 530 external static _identical(String path1, String path2); | 530 external static _identical(String path1, String path2); |
| 531 external static _resolveSymbolicLinks(String path); | 531 external static _resolveSymbolicLinks(String path); |
| 532 | 532 |
| 533 /** | |
| 534 * The directory containing [this]. If [this] is a root | |
| 535 * directory, returns [this]. | |
| 536 */ | |
| 537 Directory get parent { | |
|
Søren Gjesse
2013/10/04 12:20:16
How about
return new Directory(new Uri.file(path)
Bill Hesse
2013/10/04 12:41:06
This will not give the desired result, since it wi
| |
| 538 if (Platform.isWindows) { | |
| 539 int rootEnd = -1; | |
| 540 if (path.startsWith(_absoluteWindowsPathPattern)) { | |
| 541 // Root ends at first / or \ after the first two characters. | |
| 542 rootEnd = path.indexOf(new RegExp(r'[/\\]'), 2); | |
| 543 if (rootEnd == -1) return new Directory(path); | |
| 544 } | |
| 545 // Ignore trailing slashes - find a slash followed by a non-slash. | |
| 546 int pos = path.lastIndexOf(new RegExp(r'[/\\][^/\\]')); | |
| 547 if (pos <= rootEnd) { | |
| 548 if (rootEnd == -1) { | |
| 549 return new Directory('.'); | |
| 550 } else { | |
| 551 return new Directory(path.substring(0, rootEnd + 1)); | |
| 552 } | |
| 553 } | |
| 554 while (pos > rootEnd + 1 && | |
| 555 (path[pos - 1] == '\\' || path[pos - 1] == '/')) { | |
| 556 pos--; | |
| 557 } | |
| 558 return new Directory(path.substring(0, pos)); | |
| 559 } else { | |
| 560 // Ignore trailing slashes - find a slash followed by a non-slash. | |
| 561 int pos = path.lastIndexOf(new RegExp(r'/[^/]')); | |
| 562 if (pos < 0) return new Directory('.'); | |
| 563 while (pos > 0 && path[pos - 1] == '/') --pos; | |
| 564 if (pos == 0) return new Directory('/'); | |
| 565 return new Directory(path.substring(0, pos)); | |
| 566 } | |
| 567 } | |
| 568 | |
| 533 static int _getTypeSync(String path, bool followLinks) { | 569 static int _getTypeSync(String path, bool followLinks) { |
| 534 var result = _getType(path, followLinks); | 570 var result = _getType(path, followLinks); |
| 535 _throwIfError(result, 'Error getting type of FileSystemEntity'); | 571 _throwIfError(result, 'Error getting type of FileSystemEntity'); |
| 536 return result; | 572 return result; |
| 537 } | 573 } |
| 538 | 574 |
| 539 static Future<int> _getTypeAsync(String path, bool followLinks) { | 575 static Future<int> _getTypeAsync(String path, bool followLinks) { |
| 540 return _IOService.dispatch(_FILE_TYPE, [path, followLinks]).then((response) { | 576 return _IOService.dispatch(_FILE_TYPE, [path, followLinks]) |
| 541 if (_isErrorResponse(response)) { | 577 .then((response) { |
| 542 throw _exceptionFromResponse(response, "Error getting type", path); | 578 if (_isErrorResponse(response)) { |
| 543 } | 579 throw _exceptionFromResponse(response, "Error getting type", path); |
| 544 return response; | 580 } |
| 545 }); | 581 return response; |
| 582 }); | |
| 546 } | 583 } |
| 547 | 584 |
| 548 static _throwIfError(Object result, String msg, [String path]) { | 585 static _throwIfError(Object result, String msg, [String path]) { |
| 549 if (result is OSError) { | 586 if (result is OSError) { |
| 550 throw new FileException(msg, path, result); | 587 throw new FileException(msg, path, result); |
| 551 } else if (result is ArgumentError) { | 588 } else if (result is ArgumentError) { |
| 552 throw result; | 589 throw result; |
| 553 } | 590 } |
| 554 } | 591 } |
| 555 | 592 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 } | 698 } |
| 662 } | 699 } |
| 663 | 700 |
| 664 | 701 |
| 665 abstract class _FileSystemWatcher { | 702 abstract class _FileSystemWatcher { |
| 666 external factory _FileSystemWatcher(String path, int events, bool recursive); | 703 external factory _FileSystemWatcher(String path, int events, bool recursive); |
| 667 external static bool get isSupported; | 704 external static bool get isSupported; |
| 668 | 705 |
| 669 Stream<FileSystemEvent> get stream; | 706 Stream<FileSystemEvent> get stream; |
| 670 } | 707 } |
| OLD | NEW |