Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: sdk/lib/io/file_system_entity.dart

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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._dispatchWithNamespace(_FILE_STAT, [null, path])
129 .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
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
307 ._dispatch(_FILE_RESOLVE_SYMBOLIC_LINKS, [path]).then((response) { 308 ._dispatchWithNamespace(_FILE_RESOLVE_SYMBOLIC_LINKS, [null, path])
309 .then((response) {
308 if (_isErrorResponse(response)) { 310 if (_isErrorResponse(response)) {
309 throw _exceptionFromResponse( 311 throw _exceptionFromResponse(
310 response, "Cannot resolve symbolic links", path); 312 response, "Cannot resolve symbolic links", path);
311 } 313 }
312 return response; 314 return response;
313 }); 315 });
314 } 316 }
315 317
316 /** 318 /**
317 * Resolves the path of a file system object relative to the 319 * Resolves the path of a file system object relative to the
(...skipping 16 matching lines...) Expand all
334 * 336 *
335 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath(); 337 * var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();
336 * if (path == '') path = '.'; 338 * if (path == '') path = '.';
337 * var resolved = new File(path).resolveSymbolicLinksSync(); 339 * var resolved = new File(path).resolveSymbolicLinksSync();
338 * print(resolved); 340 * print(resolved);
339 * 341 *
340 * since `Uri.resolve` removes `..` segments. This will result in the Windows 342 * since `Uri.resolve` removes `..` segments. This will result in the Windows
341 * behavior. 343 * behavior.
342 */ 344 */
343 String resolveSymbolicLinksSync() { 345 String resolveSymbolicLinksSync() {
344 var result = _resolveSymbolicLinks(path); 346 var result = _resolveSymbolicLinks(_Namespace._namespace, path);
345 _throwIfError(result, "Cannot resolve symbolic links", path); 347 _throwIfError(result, "Cannot resolve symbolic links", path);
346 return result; 348 return result;
347 } 349 }
348 350
349 /** 351 /**
350 * Calls the operating system's stat() function on the [path] of this 352 * Calls the operating system's stat() function on the [path] of this
351 * [FileSystemEntity]. Identical to [:FileStat.stat(this.path):]. 353 * [FileSystemEntity]. Identical to [:FileStat.stat(this.path):].
352 * 354 *
353 * Returns a [:Future<FileStat>:] object containing the data returned by 355 * Returns a [:Future<FileStat>:] object containing the data returned by
354 * stat(). 356 * stat().
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 * 457 *
456 * Comparing a link to its target returns false, as does comparing two links 458 * 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 459 * that point to the same target. To check the target of a link, use
458 * Link.target explicitly to fetch it. Directory links appearing 460 * Link.target explicitly to fetch it. Directory links appearing
459 * inside a path are followed, though, to find the file system object. 461 * inside a path are followed, though, to find the file system object.
460 * 462 *
461 * Completes the returned Future with an error if one of the paths points 463 * Completes the returned Future with an error if one of the paths points
462 * to an object that does not exist. 464 * to an object that does not exist.
463 */ 465 */
464 static Future<bool> identical(String path1, String path2) { 466 static Future<bool> identical(String path1, String path2) {
465 return _IOService 467 return _File._dispatchWithNamespace(_FILE_IDENTICAL, [null, path1, path2])
466 ._dispatch(_FILE_IDENTICAL, [path1, path2]).then((response) { 468 .then((response) {
467 if (_isErrorResponse(response)) { 469 if (_isErrorResponse(response)) {
468 throw _exceptionFromResponse(response, 470 throw _exceptionFromResponse(response,
469 "Error in FileSystemEntity.identical($path1, $path2)", ""); 471 "Error in FileSystemEntity.identical($path1, $path2)", "");
470 } 472 }
471 return response; 473 return response;
472 }); 474 });
473 } 475 }
474 476
475 static final RegExp _absoluteWindowsPathPattern = 477 static final RegExp _absoluteWindowsPathPattern =
476 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); 478 new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 * 519 *
518 * Comparing a link to its target returns false, as does comparing two links 520 * 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 521 * that point to the same target. To check the target of a link, use
520 * Link.target explicitly to fetch it. Directory links appearing 522 * Link.target explicitly to fetch it. Directory links appearing
521 * inside a path are followed, though, to find the file system object. 523 * inside a path are followed, though, to find the file system object.
522 * 524 *
523 * Throws an error if one of the paths points to an object that does not 525 * Throws an error if one of the paths points to an object that does not
524 * exist. 526 * exist.
525 */ 527 */
526 static bool identicalSync(String path1, String path2) { 528 static bool identicalSync(String path1, String path2) {
527 var result = _identical(path1, path2); 529 var result = _identical(_Namespace._namespace, path1, path2);
528 _throwIfError(result, 'Error in FileSystemEntity.identicalSync'); 530 _throwIfError(result, 'Error in FileSystemEntity.identicalSync');
529 return result; 531 return result;
530 } 532 }
531 533
532 /** 534 /**
533 * Test if [watch] is supported on the current system. 535 * Test if [watch] is supported on the current system.
534 * 536 *
535 * OS X 10.6 and below is not supported. 537 * OS X 10.6 and below is not supported.
536 */ 538 */
537 static bool get isWatchSupported => _FileSystemWatcher.isSupported; 539 static bool get isWatchSupported => _FileSystemWatcher.isSupported;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 static bool isFileSync(String path) => 602 static bool isFileSync(String path) =>
601 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); 603 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type);
602 604
603 /** 605 /**
604 * Synchronously checks if typeSync(path) returns 606 * Synchronously checks if typeSync(path) returns
605 * FileSystemEntityType.DIRECTORY. 607 * FileSystemEntityType.DIRECTORY.
606 */ 608 */
607 static bool isDirectorySync(String path) => 609 static bool isDirectorySync(String path) =>
608 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); 610 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type);
609 611
610 external static _getType(String path, bool followLinks); 612 external static _getType(_Namespace namespace, String path, bool followLinks);
611 external static _identical(String path1, String path2); 613 external static _identical(_Namespace namespace, String path1, String path2);
612 external static _resolveSymbolicLinks(String path); 614 external static _resolveSymbolicLinks(_Namespace namespace, String path);
613 615
614 // Finds the next-to-last component when dividing at path separators. 616 // Finds the next-to-last component when dividing at path separators.
615 static final RegExp _parentRegExp = Platform.isWindows 617 static final RegExp _parentRegExp = Platform.isWindows
616 ? new RegExp(r'[^/\\][/\\]+[^/\\]') 618 ? new RegExp(r'[^/\\][/\\]+[^/\\]')
617 : new RegExp(r'[^/]/+[^/]'); 619 : new RegExp(r'[^/]/+[^/]');
618 620
619 /** 621 /**
620 * Removes the final path component of a path, using the platform's 622 * 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 623 * path separator to split the path. Will not remove the root component
622 * of a Windows path, like "C:\\" or "\\\\server_name\\". 624 * of a Windows path, like "C:\\" or "\\\\server_name\\".
(...skipping 23 matching lines...) Expand all
646 return '.'; 648 return '.';
647 } 649 }
648 } 650 }
649 651
650 /** 652 /**
651 * The directory containing [this]. 653 * The directory containing [this].
652 */ 654 */
653 Directory get parent => new Directory(parentOf(path)); 655 Directory get parent => new Directory(parentOf(path));
654 656
655 static int _getTypeSync(String path, bool followLinks) { 657 static int _getTypeSync(String path, bool followLinks) {
656 var result = _getType(path, followLinks); 658 var result = _getType(_Namespace._namespace, path, followLinks);
657 _throwIfError(result, 'Error getting type of FileSystemEntity'); 659 _throwIfError(result, 'Error getting type of FileSystemEntity');
658 return result; 660 return result;
659 } 661 }
660 662
661 static Future<int> _getTypeAsync(String path, bool followLinks) { 663 static Future<int> _getTypeAsync(String path, bool followLinks) {
662 return _IOService 664 return _File._dispatchWithNamespace(_FILE_TYPE, [null, path, followLinks])
663 ._dispatch(_FILE_TYPE, [path, followLinks]).then((response) { 665 .then((response) {
664 if (_isErrorResponse(response)) { 666 if (_isErrorResponse(response)) {
665 throw _exceptionFromResponse(response, "Error getting type", path); 667 throw _exceptionFromResponse(response, "Error getting type", path);
666 } 668 }
667 return response; 669 return response;
668 }); 670 });
669 } 671 }
670 672
671 static _throwIfError(Object result, String msg, [String path]) { 673 static _throwIfError(Object result, String msg, [String path]) {
672 if (result is OSError) { 674 if (result is OSError) {
673 throw new FileSystemException(msg, path, result); 675 throw new FileSystemException(msg, path, result);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 buffer.write(')'); 825 buffer.write(')');
824 return buffer.toString(); 826 return buffer.toString();
825 } 827 }
826 } 828 }
827 829
828 class _FileSystemWatcher { 830 class _FileSystemWatcher {
829 external static Stream<FileSystemEvent> _watch( 831 external static Stream<FileSystemEvent> _watch(
830 String path, int events, bool recursive); 832 String path, int events, bool recursive);
831 external static bool get isSupported; 833 external static bool get isSupported;
832 } 834 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698