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

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

Issue 11312122: Change List constructors. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload. Adapt code for List.fixedLength. Created 8 years 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 | « sdk/lib/html/src/native_DOMImplementation.dart ('k') | sdk/lib/io/file_impl.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 _Directory implements Directory { 6 class _Directory implements Directory {
7 static const CREATE_REQUEST = 0; 7 static const CREATE_REQUEST = 0;
8 static const DELETE_REQUEST = 1; 8 static const DELETE_REQUEST = 1;
9 static const EXISTS_REQUEST = 2; 9 static const EXISTS_REQUEST = 2;
10 static const CREATE_TEMP_REQUEST = 3; 10 static const CREATE_TEMP_REQUEST = 3;
(...skipping 11 matching lines...) Expand all
22 external static String _current(); 22 external static String _current();
23 external static _createTemp(String template); 23 external static _createTemp(String template);
24 external static int _exists(String path); 24 external static int _exists(String path);
25 external static _create(String path); 25 external static _create(String path);
26 external static _delete(String path, bool recursive); 26 external static _delete(String path, bool recursive);
27 external static _rename(String path, String newPath); 27 external static _rename(String path, String newPath);
28 external static SendPort _newServicePort(); 28 external static SendPort _newServicePort();
29 29
30 Future<bool> exists() { 30 Future<bool> exists() {
31 _ensureDirectoryService(); 31 _ensureDirectoryService();
32 List request = new List(2); 32 List request = new List.fixedLength(2);
33 request[0] = EXISTS_REQUEST; 33 request[0] = EXISTS_REQUEST;
34 request[1] = _path; 34 request[1] = _path;
35 return _directoryService.call(request).then((response) { 35 return _directoryService.call(request).then((response) {
36 if (_isErrorResponse(response)) { 36 if (_isErrorResponse(response)) {
37 throw _exceptionOrErrorFromResponse(response, "Exists failed"); 37 throw _exceptionOrErrorFromResponse(response, "Exists failed");
38 } 38 }
39 return response == 1; 39 return response == 1;
40 }); 40 });
41 } 41 }
42 42
(...skipping 27 matching lines...) Expand all
70 if (future == null) { 70 if (future == null) {
71 return new Future.immediate(this); 71 return new Future.immediate(this);
72 } else { 72 } else {
73 return future.then((result) => this); 73 return future.then((result) => this);
74 } 74 }
75 } 75 }
76 76
77 Future<Directory> create({recursive: false}) { 77 Future<Directory> create({recursive: false}) {
78 if (recursive) return createRecursively(); 78 if (recursive) return createRecursively();
79 _ensureDirectoryService(); 79 _ensureDirectoryService();
80 List request = new List(2); 80 List request = new List.fixedLength(2);
81 request[0] = CREATE_REQUEST; 81 request[0] = CREATE_REQUEST;
82 request[1] = _path; 82 request[1] = _path;
83 return _directoryService.call(request).then((response) { 83 return _directoryService.call(request).then((response) {
84 if (_isErrorResponse(response)) { 84 if (_isErrorResponse(response)) {
85 throw _exceptionOrErrorFromResponse(response, "Creation failed"); 85 throw _exceptionOrErrorFromResponse(response, "Creation failed");
86 } 86 }
87 return this; 87 return this;
88 }); 88 });
89 } 89 }
90 90
(...skipping 12 matching lines...) Expand all
103 } 103 }
104 if (recursive) return createRecursivelySync(); 104 if (recursive) return createRecursivelySync();
105 var result = _create(_path); 105 var result = _create(_path);
106 if (result is OSError) { 106 if (result is OSError) {
107 throw new DirectoryIOException("Creation failed", _path, result); 107 throw new DirectoryIOException("Creation failed", _path, result);
108 } 108 }
109 } 109 }
110 110
111 Future<Directory> createTemp() { 111 Future<Directory> createTemp() {
112 _ensureDirectoryService(); 112 _ensureDirectoryService();
113 List request = new List(2); 113 List request = new List.fixedLength(2);
114 request[0] = CREATE_TEMP_REQUEST; 114 request[0] = CREATE_TEMP_REQUEST;
115 request[1] = _path; 115 request[1] = _path;
116 return _directoryService.call(request).then((response) { 116 return _directoryService.call(request).then((response) {
117 if (_isErrorResponse(response)) { 117 if (_isErrorResponse(response)) {
118 throw _exceptionOrErrorFromResponse(response, 118 throw _exceptionOrErrorFromResponse(response,
119 "Creation of temporary directory failed"); 119 "Creation of temporary directory failed");
120 } 120 }
121 return new Directory(response); 121 return new Directory(response);
122 }); 122 });
123 } 123 }
124 124
125 Directory createTempSync() { 125 Directory createTempSync() {
126 if (_path is !String) { 126 if (_path is !String) {
127 throw new ArgumentError(); 127 throw new ArgumentError();
128 } 128 }
129 var result = _createTemp(path); 129 var result = _createTemp(path);
130 if (result is OSError) { 130 if (result is OSError) {
131 throw new DirectoryIOException("Creation of temporary directory failed", 131 throw new DirectoryIOException("Creation of temporary directory failed",
132 _path, 132 _path,
133 result); 133 result);
134 } 134 }
135 return new Directory(result); 135 return new Directory(result);
136 } 136 }
137 137
138 Future<Directory> _deleteHelper(bool recursive, String errorMsg) { 138 Future<Directory> _deleteHelper(bool recursive, String errorMsg) {
139 } 139 }
140 140
141 Future<Directory> delete({recursive: false}) { 141 Future<Directory> delete({recursive: false}) {
142 _ensureDirectoryService(); 142 _ensureDirectoryService();
143 List request = new List(3); 143 List request = new List.fixedLength(3);
144 request[0] = DELETE_REQUEST; 144 request[0] = DELETE_REQUEST;
145 request[1] = _path; 145 request[1] = _path;
146 request[2] = recursive; 146 request[2] = recursive;
147 return _directoryService.call(request).then((response) { 147 return _directoryService.call(request).then((response) {
148 if (_isErrorResponse(response)) { 148 if (_isErrorResponse(response)) {
149 throw _exceptionOrErrorFromResponse(response, "Deletion failed"); 149 throw _exceptionOrErrorFromResponse(response, "Deletion failed");
150 } 150 }
151 return this; 151 return this;
152 }); 152 });
153 } 153 }
154 154
155 void deleteSync({recursive: false}) { 155 void deleteSync({recursive: false}) {
156 if (_path is !String) { 156 if (_path is !String) {
157 throw new ArgumentError(); 157 throw new ArgumentError();
158 } 158 }
159 var result = _delete(_path, recursive); 159 var result = _delete(_path, recursive);
160 if (result is OSError) { 160 if (result is OSError) {
161 throw new DirectoryIOException("Deletion failed", _path, result); 161 throw new DirectoryIOException("Deletion failed", _path, result);
162 } 162 }
163 } 163 }
164 164
165 Future<Directory> rename(String newPath) { 165 Future<Directory> rename(String newPath) {
166 _ensureDirectoryService(); 166 _ensureDirectoryService();
167 List request = new List(3); 167 List request = new List.fixedLength(3);
168 request[0] = RENAME_REQUEST; 168 request[0] = RENAME_REQUEST;
169 request[1] = _path; 169 request[1] = _path;
170 request[2] = newPath; 170 request[2] = newPath;
171 return _directoryService.call(request).then((response) { 171 return _directoryService.call(request).then((response) {
172 if (_isErrorResponse(response)) { 172 if (_isErrorResponse(response)) {
173 throw _exceptionOrErrorFromResponse(response, "Rename failed"); 173 throw _exceptionOrErrorFromResponse(response, "Rename failed");
174 } 174 }
175 return new Directory(newPath); 175 return new Directory(newPath);
176 }); 176 });
177 } 177 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 const int LIST_DIRECTORY = 0; 256 const int LIST_DIRECTORY = 0;
257 const int LIST_FILE = 1; 257 const int LIST_FILE = 1;
258 const int LIST_ERROR = 2; 258 const int LIST_ERROR = 2;
259 const int LIST_DONE = 3; 259 const int LIST_DONE = 3;
260 260
261 final int RESPONSE_TYPE = 0; 261 final int RESPONSE_TYPE = 0;
262 final int RESPONSE_PATH = 1; 262 final int RESPONSE_PATH = 1;
263 final int RESPONSE_COMPLETE = 1; 263 final int RESPONSE_COMPLETE = 1;
264 final int RESPONSE_ERROR = 2; 264 final int RESPONSE_ERROR = 2;
265 265
266 List request = new List(3); 266 List request = new List.fixedLength(3);
267 request[0] = _Directory.LIST_REQUEST; 267 request[0] = _Directory.LIST_REQUEST;
268 request[1] = path; 268 request[1] = path;
269 request[2] = recursive; 269 request[2] = recursive;
270 ReceivePort responsePort = new ReceivePort(); 270 ReceivePort responsePort = new ReceivePort();
271 // Use a separate directory service port for each listing as 271 // Use a separate directory service port for each listing as
272 // listing operations on the same directory can run in parallel. 272 // listing operations on the same directory can run in parallel.
273 _Directory._newServicePort().send(request, responsePort.toSendPort()); 273 _Directory._newServicePort().send(request, responsePort.toSendPort());
274 responsePort.receive((message, replyTo) { 274 responsePort.receive((message, replyTo) {
275 if (message is !List || message[RESPONSE_TYPE] is !int) { 275 if (message is !List || message[RESPONSE_TYPE] is !int) {
276 responsePort.close(); 276 responsePort.close();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } else { 333 } else {
334 throw e; 334 throw e;
335 } 335 }
336 } 336 }
337 337
338 Function _onDir; 338 Function _onDir;
339 Function _onFile; 339 Function _onFile;
340 Function _onDone; 340 Function _onDone;
341 Function _onError; 341 Function _onError;
342 } 342 }
OLDNEW
« no previous file with comments | « sdk/lib/html/src/native_DOMImplementation.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698