| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Asynchronously calls the operating system's stat() function on [path]. | 67 * Asynchronously calls the operating system's stat() function on [path]. |
| 68 * Returns a Future which completes with a [FileStat] object containing | 68 * Returns a Future which completes with a [FileStat] object containing |
| 69 * the data returned by stat(). | 69 * the data returned by stat(). |
| 70 * If the call fails, completes the future with a [FileStat] object with | 70 * If the call fails, completes the future with a [FileStat] object with |
| 71 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. | 71 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. |
| 72 */ | 72 */ |
| 73 static Future<FileStat> stat(String path) { | 73 static Future<FileStat> stat(String path) { |
| 74 // Get a new file service port for each request. We could also cache one. | 74 return IOService.dispatch(FILE_STAT, [path]).then((response) { |
| 75 var service = _FileUtils._newServicePort(); | |
| 76 List request = new List(2); | |
| 77 request[0] = _STAT_REQUEST; | |
| 78 request[1] = path; | |
| 79 return service.call(request).then((response) { | |
| 80 if (_isErrorResponse(response)) { | 75 if (_isErrorResponse(response)) { |
| 81 throw _exceptionFromResponse(response, | 76 throw _exceptionFromResponse(response, |
| 82 "Error getting stat", | 77 "Error getting stat", |
| 83 path); | 78 path); |
| 84 } | 79 } |
| 85 // Unwrap the real list from the "I'm not an error" wrapper. | 80 // Unwrap the real list from the "I'm not an error" wrapper. |
| 86 List data = response[1]; | 81 List data = response[1]; |
| 87 return new FileStat._internal( | 82 return new FileStat._internal( |
| 88 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000), | 83 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000), |
| 89 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000), | 84 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000), |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 * | 229 * |
| 235 * On Windows, symbolic links are resolved to their target before applying | 230 * On Windows, symbolic links are resolved to their target before applying |
| 236 * a '..' that follows, and on other platforms, the '..' is applied to the | 231 * a '..' that follows, and on other platforms, the '..' is applied to the |
| 237 * symbolic link without resolving it. The second behavior can be emulated | 232 * symbolic link without resolving it. The second behavior can be emulated |
| 238 * on Windows by processing any '..' segments before calling | 233 * on Windows by processing any '..' segments before calling |
| 239 * [resolveSymbolicLinks]. One way of doing this is with the URI class: | 234 * [resolveSymbolicLinks]. One way of doing this is with the URI class: |
| 240 * [:new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();], | 235 * [:new Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();], |
| 241 * since [resolve] removes '..' segments. | 236 * since [resolve] removes '..' segments. |
| 242 */ | 237 */ |
| 243 Future<String> resolveSymbolicLinks() { | 238 Future<String> resolveSymbolicLinks() { |
| 244 // Get a new file service port for each request. We could also cache one. | 239 return IOService.dispatch(FILE_RESOLVE_SYMBOLIC_LINKS, [path]) |
| 245 var service = _FileUtils._newServicePort(); | 240 .then((response) { |
| 246 List request = new List(2); | 241 if (_isErrorResponse(response)) { |
| 247 request[0] = _RESOLVE_SYMBOLIC_LINKS_REQUEST; | 242 throw _exceptionFromResponse(response, |
| 248 request[1] = path; | 243 "Cannot resolve symbolic links", |
| 249 return service.call(request).then((response) { | 244 path); |
| 250 if (_isErrorResponse(response)) { | 245 } |
| 251 throw _exceptionFromResponse(response, | 246 return response; |
| 252 "Cannot resolve symbolic links", | 247 }); |
| 253 path); | |
| 254 } | |
| 255 return response; | |
| 256 }); | |
| 257 } | 248 } |
| 258 | 249 |
| 259 /** | 250 /** |
| 260 * Resolves the path of a file system object relative to the | 251 * Resolves the path of a file system object relative to the |
| 261 * current working directory, resolving all symbolic links on | 252 * current working directory, resolving all symbolic links on |
| 262 * the path and resolving all '..' and '.' path segments. | 253 * the path and resolving all '..' and '.' path segments. |
| 263 * | 254 * |
| 264 * [resolveSymbolicLinksSync] uses the operating system's native | 255 * [resolveSymbolicLinksSync] uses the operating system's native |
| 265 * filesystem api to resolve the path, using the realpath function | 256 * filesystem api to resolve the path, using the realpath function |
| 266 * on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. | 257 * on linux and Mac OS, and the GetFinalPathNameByHandle function on Windows. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 * | 374 * |
| 384 * Comparing a link to its target returns false, as does comparing two links | 375 * Comparing a link to its target returns false, as does comparing two links |
| 385 * that point to the same target. To check the target of a link, use | 376 * that point to the same target. To check the target of a link, use |
| 386 * Link.target explicitly to fetch it. Directory links appearing | 377 * Link.target explicitly to fetch it. Directory links appearing |
| 387 * inside a path are followed, though, to find the file system object. | 378 * inside a path are followed, though, to find the file system object. |
| 388 * | 379 * |
| 389 * Completes the returned Future with an error if one of the paths points | 380 * Completes the returned Future with an error if one of the paths points |
| 390 * to an object that does not exist. | 381 * to an object that does not exist. |
| 391 */ | 382 */ |
| 392 static Future<bool> identical(String path1, String path2) { | 383 static Future<bool> identical(String path1, String path2) { |
| 393 // Get a new file service port for each request. We could also cache one. | 384 return IOService.dispatch(FILE_IDENTICAL, [path1, path2]).then((response) { |
| 394 var service = _FileUtils._newServicePort(); | |
| 395 List request = new List(3); | |
| 396 request[0] = _IDENTICAL_REQUEST; | |
| 397 request[1] = path1; | |
| 398 request[2] = path2; | |
| 399 return service.call(request).then((response) { | |
| 400 if (_isErrorResponse(response)) { | 385 if (_isErrorResponse(response)) { |
| 401 throw _exceptionFromResponse(response, | 386 throw _exceptionFromResponse(response, |
| 402 "Error in FileSystemEntity.identical($path1, $path2)", ""); | 387 "Error in FileSystemEntity.identical($path1, $path2)", ""); |
| 403 } | 388 } |
| 404 return response; | 389 return response; |
| 405 }); | 390 }); |
| 406 } | 391 } |
| 407 | 392 |
| 408 static final RegExp _absoluteWindowsPathPattern = | 393 static final RegExp _absoluteWindowsPathPattern = |
| 409 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); | 394 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 external static _identical(String path1, String path2); | 530 external static _identical(String path1, String path2); |
| 546 external static _resolveSymbolicLinks(String path); | 531 external static _resolveSymbolicLinks(String path); |
| 547 | 532 |
| 548 static int _getTypeSync(String path, bool followLinks) { | 533 static int _getTypeSync(String path, bool followLinks) { |
| 549 var result = _getType(path, followLinks); | 534 var result = _getType(path, followLinks); |
| 550 _throwIfError(result, 'Error getting type of FileSystemEntity'); | 535 _throwIfError(result, 'Error getting type of FileSystemEntity'); |
| 551 return result; | 536 return result; |
| 552 } | 537 } |
| 553 | 538 |
| 554 static Future<int> _getTypeAsync(String path, bool followLinks) { | 539 static Future<int> _getTypeAsync(String path, bool followLinks) { |
| 555 // Get a new file service port for each request. We could also cache one. | 540 return IOService.dispatch(FILE_TYPE, [path, followLinks]).then((response) { |
| 556 var service = _FileUtils._newServicePort(); | |
| 557 List request = new List(3); | |
| 558 request[0] = _TYPE_REQUEST; | |
| 559 request[1] = path; | |
| 560 request[2] = followLinks; | |
| 561 return service.call(request).then((response) { | |
| 562 if (_isErrorResponse(response)) { | 541 if (_isErrorResponse(response)) { |
| 563 throw _exceptionFromResponse(response, "Error getting type", path); | 542 throw _exceptionFromResponse(response, "Error getting type", path); |
| 564 } | 543 } |
| 565 return response; | 544 return response; |
| 566 }); | 545 }); |
| 567 } | 546 } |
| 568 | 547 |
| 569 static _throwIfError(Object result, String msg, [String path]) { | 548 static _throwIfError(Object result, String msg, [String path]) { |
| 570 if (result is OSError) { | 549 if (result is OSError) { |
| 571 throw new FileException(msg, path, result); | 550 throw new FileException(msg, path, result); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 661 } |
| 683 } | 662 } |
| 684 | 663 |
| 685 | 664 |
| 686 abstract class _FileSystemWatcher { | 665 abstract class _FileSystemWatcher { |
| 687 external factory _FileSystemWatcher(String path, int events, bool recursive); | 666 external factory _FileSystemWatcher(String path, int events, bool recursive); |
| 688 external static bool get isSupported; | 667 external static bool get isSupported; |
| 689 | 668 |
| 690 Stream<FileSystemEvent> get stream; | 669 Stream<FileSystemEvent> get stream; |
| 691 } | 670 } |
| OLD | NEW |