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

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

Issue 156633002: Change FileStat static methods to return NOT_FOUND instead for throwing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/io/file_stat_test.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 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 17 matching lines...) Expand all
28 */ 28 */
29 class FileStat { 29 class FileStat {
30 // These must agree with enum FileStat in file.h. 30 // These must agree with enum FileStat in file.h.
31 static const _TYPE = 0; 31 static const _TYPE = 0;
32 static const _CHANGED_TIME = 1; 32 static const _CHANGED_TIME = 1;
33 static const _MODIFIED_TIME = 2; 33 static const _MODIFIED_TIME = 2;
34 static const _ACCESSED_TIME = 3; 34 static const _ACCESSED_TIME = 3;
35 static const _MODE = 4; 35 static const _MODE = 4;
36 static const _SIZE = 5; 36 static const _SIZE = 5;
37 37
38 static const _notFound = const FileStat._internalNotFound();
39
38 /** 40 /**
39 * The time of the last change to the data or metadata of the file system 41 * The time of the last change to the data or metadata of the file system
40 * object. On Windows platforms, this is instead the file creation time. 42 * object. On Windows platforms, this is instead the file creation time.
41 */ 43 */
42 final DateTime changed; 44 final DateTime changed;
43 /** 45 /**
44 * The time of the last change to the data of the file system 46 * The time of the last change to the data of the file system
45 * object. 47 * object.
46 */ 48 */
47 final DateTime modified; 49 final DateTime modified;
(...skipping 16 matching lines...) Expand all
64 /** 66 /**
65 * The size of the file system object. 67 * The size of the file system object.
66 */ 68 */
67 final int size; 69 final int size;
68 70
69 FileStat._internal(this.changed, 71 FileStat._internal(this.changed,
70 this.modified, 72 this.modified,
71 this.accessed, 73 this.accessed,
72 this.type, 74 this.type,
73 this.mode, 75 this.mode,
74 this.size); 76 this.size);
Anders Johnsen 2014/02/06 10:20:16 newline
Søren Gjesse 2014/02/06 11:27:27 Done.
77 const FileStat._internalNotFound() :
78 changed = null, modified = null, accessed = null,
79 type = FileSystemEntityType.NOT_FOUND, mode = 0, size = -1;
75 80
76 external static List<int> _statSync(String path); 81 external static List<int> _statSync(String path);
77 82
78 83
79 /** 84 /**
80 * Calls the operating system's stat() function on [path]. 85 * Calls the operating system's stat() function on [path].
81 * Returns a [FileStat] object containing the data returned by stat(). 86 * Returns a [FileStat] object containing the data returned by stat().
82 * If the call fails, returns a [FileStat] object with .type set to 87 * If the call fails, returns a [FileStat] object with .type set to
83 * FileSystemEntityType.NOT_FOUND and the other fields invalid. 88 * FileSystemEntityType.NOT_FOUND and the other fields invalid.
84 */ 89 */
85 static FileStat statSync(String path) { 90 static FileStat statSync(String path) {
86 // Trailing path is not supported on Windows. 91 // Trailing path is not supported on Windows.
87 if (Platform.isWindows) { 92 if (Platform.isWindows) {
88 path = FileSystemEntity._trimTrailingPathSeparators(path); 93 path = FileSystemEntity._trimTrailingPathSeparators(path);
89 } 94 }
90 var data = _statSync(path); 95 var data = _statSync(path);
91 if (data is OSError) throw data; 96 if (data is OSError) return FileStat._notFound;
92 return new FileStat._internal( 97 return new FileStat._internal(
93 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000), 98 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000),
94 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000), 99 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000),
95 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME] * 1000), 100 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME] * 1000),
96 FileSystemEntityType._lookup(data[_TYPE]), 101 FileSystemEntityType._lookup(data[_TYPE]),
97 data[_MODE], 102 data[_MODE],
98 data[_SIZE]); 103 data[_SIZE]);
99 } 104 }
100 105
101 /** 106 /**
102 * Asynchronously calls the operating system's stat() function on [path]. 107 * Asynchronously calls the operating system's stat() function on [path].
103 * Returns a Future which completes with a [FileStat] object containing 108 * Returns a Future which completes with a [FileStat] object containing
104 * the data returned by stat(). 109 * the data returned by stat().
105 * If the call fails, completes the future with a [FileStat] object with 110 * If the call fails, completes the future with a [FileStat] object with
106 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. 111 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
107 */ 112 */
108 static Future<FileStat> stat(String path) { 113 static Future<FileStat> stat(String path) {
109 // Trailing path is not supported on Windows. 114 // Trailing path is not supported on Windows.
110 if (Platform.isWindows) { 115 if (Platform.isWindows) {
111 path = FileSystemEntity._trimTrailingPathSeparators(path); 116 path = FileSystemEntity._trimTrailingPathSeparators(path);
112 } 117 }
113 return _IOService.dispatch(_FILE_STAT, [path]).then((response) { 118 return _IOService.dispatch(_FILE_STAT, [path]).then((response) {
114 if (_isErrorResponse(response)) { 119 if (_isErrorResponse(response)) {
115 throw _exceptionFromResponse(response, 120 return FileStat._notFound;
116 "Error getting stat",
117 path);
118 } 121 }
119 // Unwrap the real list from the "I'm not an error" wrapper. 122 // Unwrap the real list from the "I'm not an error" wrapper.
120 List data = response[1]; 123 List data = response[1];
121 return new FileStat._internal( 124 return new FileStat._internal(
122 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000), 125 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000),
123 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000), 126 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000),
124 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME] * 1000), 127 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME] * 1000),
125 FileSystemEntityType._lookup(data[_TYPE]), 128 FileSystemEntityType._lookup(data[_TYPE]),
126 data[_MODE], 129 data[_MODE],
127 data[_SIZE]); 130 data[_SIZE]);
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 return buffer.toString(); 767 return buffer.toString();
765 } 768 }
766 } 769 }
767 770
768 771
769 class _FileSystemWatcher { 772 class _FileSystemWatcher {
770 external static Stream<FileSystemEvent> watch( 773 external static Stream<FileSystemEvent> watch(
771 String path, int events, bool recursive); 774 String path, int events, bool recursive);
772 external static bool get isSupported; 775 external static bool get isSupported;
773 } 776 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/file_stat_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698