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

Side by Side Diff: runtime/bin/directory_impl.dart

Issue 8417023: Add type checks to directory listing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | « runtime/bin/directory.dart ('k') | tests/standalone/src/DirectoryInvalidArgumentsTest.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 5
6 class DirectoryException {
7 String toString() { return "DirectoryException: $message"; }
8 const DirectoryException(String this.message);
9 final String message;
10 }
11
12
13 class _DirectoryListingIsolate extends Isolate { 6 class _DirectoryListingIsolate extends Isolate {
14 7
15 _DirectoryListingIsolate() : super.heavy(); 8 _DirectoryListingIsolate() : super.heavy();
16 9
17 void main() { 10 void main() {
18 port.receive((message, replyTo) { 11 port.receive((message, replyTo) {
19 _list(message['dir'], 12 bool started = _list(message['dir'],
20 message['recursive'], 13 message['recursive'],
21 message['dirPort'], 14 message['dirPort'],
22 message['filePort'], 15 message['filePort'],
23 message['donePort'], 16 message['donePort'],
24 message['errorPort']); 17 message['errorPort']);
25 replyTo.send(true); 18 replyTo.send(started);
26 }); 19 });
27 } 20 }
28 21
29 void _list(String dir, 22 bool _list(String dir,
30 bool recursive, 23 bool recursive,
31 SendPort dirPort, 24 SendPort dirPort,
32 SendPort filePort, 25 SendPort filePort,
33 SendPort donePort, 26 SendPort donePort,
34 SendPort errorPort) native "Directory_List"; 27 SendPort errorPort) native "Directory_List";
35 } 28 }
36 29
37 30
38 class _Directory implements Directory { 31 class _Directory implements Directory {
39 32
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 listingParameters['dirPort'] = dirPort.toSendPort(); 77 listingParameters['dirPort'] = dirPort.toSendPort();
85 } 78 }
86 if (_fileHandler !== null) { 79 if (_fileHandler !== null) {
87 filePort = new ReceivePort(); 80 filePort = new ReceivePort();
88 filePort.receive((String file, ignored) { 81 filePort.receive((String file, ignored) {
89 _fileHandler(file); 82 _fileHandler(file);
90 }); 83 });
91 listingParameters['filePort'] = filePort.toSendPort(); 84 listingParameters['filePort'] = filePort.toSendPort();
92 } 85 }
93 if (_doneHandler !== null) { 86 if (_doneHandler !== null) {
94 donePort = new ReceivePort(); 87 donePort = new ReceivePort.singleShot();
95 donePort.receive((bool completed, ignored) { 88 donePort.receive((bool completed, ignored) {
96 _doneHandler(completed); 89 _doneHandler(completed);
97 }); 90 });
98 listingParameters['donePort'] = donePort.toSendPort(); 91 listingParameters['donePort'] = donePort.toSendPort();
99 } 92 }
100 if (_errorHandler !== null) { 93 if (_errorHandler !== null) {
101 errorPort = new ReceivePort(); 94 errorPort = new ReceivePort.singleShot();
102 errorPort.receive((String error, ignored) { 95 errorPort.receive((String error, ignored) {
103 _errorHandler(error); 96 _errorHandler(error);
104 }); 97 });
105 listingParameters['errorPort'] = errorPort.toSendPort(); 98 listingParameters['errorPort'] = errorPort.toSendPort();
106 } 99 }
107 100
108 // Close ports when listing is done. 101 // Close ports when listing is done.
109 ReceivePort closePortsPort = new ReceivePort(); 102 ReceivePort closePortsPort = new ReceivePort();
110 closePortsPort.receive((message, replyTo) { 103 closePortsPort.receive((message, replyTo) {
104 if (!message) {
105 errorPort.toSendPort().send(
106 "Failed to list directory: $_path recursive: $recursive");
107 donePort.toSendPort().send(false);
108 } else {
109 _closePort(errorPort);
110 _closePort(donePort);
111 }
111 _closePort(dirPort); 112 _closePort(dirPort);
112 _closePort(filePort); 113 _closePort(filePort);
Søren Gjesse 2011/10/28 13:05:55 Shouldn't the error port be closed if everything e
Mads Ager (google) 2011/10/28 15:58:16 It is on line 109. If listing does not start the s
113 _closePort(donePort);
114 _closePort(errorPort);
115 _closePort(closePortsPort); 114 _closePort(closePortsPort);
116 }); 115 });
117 116
118 // Send the listing parameters to the isolate. 117 // Send the listing parameters to the isolate.
119 port.send(listingParameters, closePortsPort.toSendPort()); 118 port.send(listingParameters, closePortsPort.toSendPort());
120 }); 119 });
121 } 120 }
122 121
123 void setDirHandler(void dirHandler(String dir)) { 122 void setDirHandler(void dirHandler(String dir)) {
124 _dirHandler = dirHandler; 123 _dirHandler = dirHandler;
(...skipping 23 matching lines...) Expand all
148 bool _create(String path) native "Directory_Create"; 147 bool _create(String path) native "Directory_Create";
149 bool _delete(String path) native "Directory_Delete"; 148 bool _delete(String path) native "Directory_Delete";
150 149
151 var _dirHandler; 150 var _dirHandler;
152 var _fileHandler; 151 var _fileHandler;
153 var _doneHandler; 152 var _doneHandler;
154 var _errorHandler; 153 var _errorHandler;
155 154
156 String _path; 155 String _path;
157 } 156 }
OLDNEW
« no previous file with comments | « runtime/bin/directory.dart ('k') | tests/standalone/src/DirectoryInvalidArgumentsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698