Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 11 static const LIST_REQUEST = 4; | 11 static const LIST_REQUEST = 4; |
| 12 static const RENAME_REQUEST = 5; | 12 static const RENAME_REQUEST = 5; |
| 13 | 13 |
| 14 static const SUCCESS_RESPONSE = 0; | 14 static const SUCCESS_RESPONSE = 0; |
| 15 static const ILLEGAL_ARGUMENT_RESPONSE = 1; | 15 static const ILLEGAL_ARGUMENT_RESPONSE = 1; |
| 16 static const OSERROR_RESPONSE = 2; | 16 static const OSERROR_RESPONSE = 2; |
| 17 | 17 |
| 18 _Directory(String this._path); | 18 _Directory(String this._path); |
| 19 _Directory.fromPath(Path path) : this(path.toNativePath()); | 19 _Directory.fromPath(Path path) : this(path.toNativePath()); |
| 20 _Directory.current() : this(_current()); | 20 _Directory.current() : this(_current()); |
| 21 | 21 |
| 22 static String _current() native "Directory_Current"; | 22 external static String _current(); |
| 23 static _createTemp(String template) native "Directory_CreateTemp"; | 23 external static _createTemp(String template); |
|
Søren Gjesse
2012/10/30 09:28:32
Should we use void where there is no return type?
Mads Ager (google)
2012/10/30 11:12:40
There is a return value but it can be either an OS
| |
| 24 static int _exists(String path) native "Directory_Exists"; | 24 external static int _exists(String path); |
| 25 static _create(String path) native "Directory_Create"; | 25 external static _create(String path); |
| 26 static _delete(String path, bool recursive) native "Directory_Delete"; | 26 external static _delete(String path, bool recursive); |
| 27 static _rename(String path, String newPath) native "Directory_Rename"; | 27 external static _rename(String path, String newPath); |
| 28 static SendPort _newServicePort() native "Directory_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(2); |
| 33 request[0] = EXISTS_REQUEST; | 33 request[0] = EXISTS_REQUEST; |
| 34 request[1] = _path; | 34 request[1] = _path; |
| 35 return _directoryService.call(request).transform((response) { | 35 return _directoryService.call(request).transform((response) { |
| 36 if (_isErrorResponse(response)) { | 36 if (_isErrorResponse(response)) { |
| 37 throw _exceptionFromResponse(response, "Exists failed"); | 37 throw _exceptionFromResponse(response, "Exists failed"); |
| 38 } | 38 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 List request = new List(3); | 106 List request = new List(3); |
| 107 request[0] = DELETE_REQUEST; | 107 request[0] = DELETE_REQUEST; |
| 108 request[1] = _path; | 108 request[1] = _path; |
| 109 request[2] = recursive; | 109 request[2] = recursive; |
| 110 return _directoryService.call(request).transform((response) { | 110 return _directoryService.call(request).transform((response) { |
| 111 if (_isErrorResponse(response)) { | 111 if (_isErrorResponse(response)) { |
| 112 throw _exceptionFromResponse(response, errorMsg); | 112 throw _exceptionFromResponse(response, errorMsg); |
| 113 } | 113 } |
| 114 return this; | 114 return this; |
| 115 }); | 115 }); |
| 116 return completer.future; | |
| 117 } | 116 } |
| 118 | 117 |
| 119 Future<Directory> delete() { | 118 Future<Directory> delete() { |
| 120 return _deleteHelper(false, "Deletion failed"); | 119 return _deleteHelper(false, "Deletion failed"); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void deleteSync() { | 122 void deleteSync() { |
| 124 if (_path is !String) { | 123 if (_path is !String) { |
| 125 throw new ArgumentError(); | 124 throw new ArgumentError(); |
| 126 } | 125 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 DirectoryLister list({bool recursive: false}) { | 171 DirectoryLister list({bool recursive: false}) { |
| 173 return new _DirectoryLister(_path, recursive); | 172 return new _DirectoryLister(_path, recursive); |
| 174 } | 173 } |
| 175 | 174 |
| 176 String get path { return _path; } | 175 String get path { return _path; } |
| 177 | 176 |
| 178 bool _isErrorResponse(response) { | 177 bool _isErrorResponse(response) { |
| 179 return response is List && response[0] != _SUCCESS_RESPONSE; | 178 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 180 } | 179 } |
| 181 | 180 |
| 182 Exception _exceptionFromResponse(response, String message) { | 181 _exceptionFromResponse(response, String message) { |
|
Søren Gjesse
2012/10/30 09:28:32
_exceptionFromResponse -> _exceptionOrErrorFromRes
Mads Ager (google)
2012/10/30 11:12:40
Done.
| |
| 183 assert(_isErrorResponse(response)); | 182 assert(_isErrorResponse(response)); |
| 184 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { | 183 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { |
| 185 case _ILLEGAL_ARGUMENT_RESPONSE: | 184 case _ILLEGAL_ARGUMENT_RESPONSE: |
| 186 return new ArgumentError(); | 185 return new ArgumentError(); |
| 187 case _OSERROR_RESPONSE: | 186 case _OSERROR_RESPONSE: |
| 188 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 187 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 189 response[_OSERROR_RESPONSE_ERROR_CODE]); | 188 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 190 return new DirectoryIOException(message, _path, err); | 189 return new DirectoryIOException(message, _path, err); |
| 191 default: | 190 default: |
| 192 return new Exception("Unknown error"); | 191 return new Exception("Unknown error"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } else { | 284 } else { |
| 286 throw e; | 285 throw e; |
| 287 } | 286 } |
| 288 } | 287 } |
| 289 | 288 |
| 290 Function _onDir; | 289 Function _onDir; |
| 291 Function _onFile; | 290 Function _onFile; |
| 292 Function _onDone; | 291 Function _onDone; |
| 293 Function _onError; | 292 Function _onError; |
| 294 } | 293 } |
| OLD | NEW |