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

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

Issue 14907002: dart:io | Implement asynchronous versions of FileSystemEntity methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add implementation of FileSystemEntity.type, and refactor error handling. Created 7 years, 7 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 | « sdk/lib/io/directory_impl.dart ('k') | sdk/lib/io/file_system_entity.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 // Read the file in blocks of size 64k. 7 // Read the file in blocks of size 64k.
8 const int _BLOCK_SIZE = 64 * 1024; 8 const int _BLOCK_SIZE = 64 * 1024;
9 9
10 10
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 const int _LAST_MODIFIED_REQUEST = 12; 191 const int _LAST_MODIFIED_REQUEST = 12;
192 const int _FLUSH_REQUEST = 13; 192 const int _FLUSH_REQUEST = 13;
193 const int _READ_BYTE_REQUEST = 14; 193 const int _READ_BYTE_REQUEST = 14;
194 const int _WRITE_BYTE_REQUEST = 15; 194 const int _WRITE_BYTE_REQUEST = 15;
195 const int _READ_REQUEST = 16; 195 const int _READ_REQUEST = 16;
196 const int _READ_LIST_REQUEST = 17; 196 const int _READ_LIST_REQUEST = 17;
197 const int _WRITE_LIST_REQUEST = 18; 197 const int _WRITE_LIST_REQUEST = 18;
198 const int _CREATE_LINK_REQUEST = 19; 198 const int _CREATE_LINK_REQUEST = 19;
199 const int _DELETE_LINK_REQUEST = 20; 199 const int _DELETE_LINK_REQUEST = 20;
200 const int _LINK_TARGET_REQUEST = 21; 200 const int _LINK_TARGET_REQUEST = 21;
201 201 const int _TYPE_REQUEST = 22;
202 // Base class for _File and _RandomAccessFile with shared functions. 202 const int _IDENTICAL_REQUEST = 23;
203 class _FileBase {
204 bool _isErrorResponse(response) {
205 return response is List && response[0] != _SUCCESS_RESPONSE;
206 }
207
208 _exceptionFromResponse(response, String message) {
209 assert(_isErrorResponse(response));
210 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) {
211 case _ILLEGAL_ARGUMENT_RESPONSE:
212 return new ArgumentError();
213 case _OSERROR_RESPONSE:
214 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE],
215 response[_OSERROR_RESPONSE_ERROR_CODE]);
216 return new FileIOException(message, err);
217 case _FILE_CLOSED_RESPONSE:
218 return new FileIOException("File closed");
219 default:
220 return new Exception("Unknown error");
221 }
222 }
223 }
224 203
225 // TODO(ager): The only reason for this class is that the patching 204 // TODO(ager): The only reason for this class is that the patching
226 // mechanism doesn't seem to like patching a private top level 205 // mechanism doesn't seem to like patching a private top level
227 // function. 206 // function.
228 class _FileUtils { 207 class _FileUtils {
229 external static SendPort _newServicePort(); 208 external static SendPort _newServicePort();
230 } 209 }
231 210
232 // Class for encapsulating the native implementation of files. 211 // Class for encapsulating the native implementation of files.
233 class _File extends _FileBase implements File { 212 class _File implements File {
234 // Constructor for file. 213 // Constructor for file.
235 _File(String this._path) { 214 _File(String this._path) {
236 if (_path is! String) { 215 if (_path is! String) {
237 throw new ArgumentError('${Error.safeToString(_path)} ' 216 throw new ArgumentError('${Error.safeToString(_path)} '
238 'is not a String'); 217 'is not a String');
239 } 218 }
240 } 219 }
241 220
242 // Constructor from Path for file. 221 // Constructor from Path for file.
243 _File.fromPath(Path path) : this(path.toNativePath()); 222 _File.fromPath(Path path) : this(path.toNativePath());
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 throw new FileIOException(msg, result); 559 throw new FileIOException(msg, result);
581 } 560 }
582 } 561 }
583 562
584 final String _path; 563 final String _path;
585 564
586 SendPort _fileService; 565 SendPort _fileService;
587 } 566 }
588 567
589 568
590 class _RandomAccessFile extends _FileBase implements RandomAccessFile { 569 class _RandomAccessFile implements RandomAccessFile {
591 _RandomAccessFile(int this._id, String this._path); 570 _RandomAccessFile(int this._id, String this._path);
592 571
593 Future<RandomAccessFile> close() { 572 Future<RandomAccessFile> close() {
594 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 573 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
595 if (closed) return _completeWithClosedException(completer); 574 if (closed) return _completeWithClosedException(completer);
596 _ensureFileService(); 575 _ensureFileService();
597 List request = new List(2); 576 List request = new List(2);
598 request[0] = _CLOSE_REQUEST; 577 request[0] = _CLOSE_REQUEST;
599 request[1] = _id; 578 request[1] = _id;
600 // Set the id_ to 0 (NULL) to ensure the no more async requests 579 // Set the id_ to 0 (NULL) to ensure the no more async requests
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 new FileIOException("File closed '$_path'")); 1009 new FileIOException("File closed '$_path'"));
1031 }); 1010 });
1032 return completer.future; 1011 return completer.future;
1033 } 1012 }
1034 1013
1035 final String _path; 1014 final String _path;
1036 int _id; 1015 int _id;
1037 1016
1038 SendPort _fileService; 1017 SendPort _fileService;
1039 } 1018 }
OLDNEW
« no previous file with comments | « sdk/lib/io/directory_impl.dart ('k') | sdk/lib/io/file_system_entity.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698