| 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 class _Directory implements Directory { | 7 class _Directory implements Directory { |
| 8 static const CREATE_REQUEST = 0; | 8 static const CREATE_REQUEST = 0; |
| 9 static const DELETE_REQUEST = 1; | 9 static const DELETE_REQUEST = 1; |
| 10 static const EXISTS_REQUEST = 2; | 10 static const EXISTS_REQUEST = 2; |
| 11 static const CREATE_TEMP_REQUEST = 3; | 11 static const CREATE_TEMP_REQUEST = 3; |
| 12 static const LIST_REQUEST = 4; | 12 static const LIST_REQUEST = 4; |
| 13 static const RENAME_REQUEST = 5; | 13 static const RENAME_REQUEST = 5; |
| 14 | 14 |
| 15 static const SUCCESS_RESPONSE = 0; | 15 static const SUCCESS_RESPONSE = 0; |
| 16 static const ILLEGAL_ARGUMENT_RESPONSE = 1; | 16 static const ILLEGAL_ARGUMENT_RESPONSE = 1; |
| 17 static const OSERROR_RESPONSE = 2; | 17 static const OSERROR_RESPONSE = 2; |
| 18 | 18 |
| 19 _Directory(String this._path); | 19 _Directory(String this._path); |
| 20 _Directory.fromPath(Path path) : this(path.toNativePath()); | 20 _Directory.fromPath(Path path) : this(path.toNativePath()); |
| 21 _Directory.current() : this(_current()); | 21 _Directory.current() : this(_current()); |
| 22 | 22 |
| 23 external static String _current(); | 23 external static String _current(); |
| 24 external static _createTemp(String template); | 24 external static _createTemp(String template); |
| 25 external static int _exists(String path); | 25 external static int _exists(String path); |
| 26 external static _create(String path); | 26 external static _create(String path); |
| 27 external static _delete(String path, bool recursive); | 27 external static _delete(String path, bool recursive); |
| 28 external static _rename(String path, String newPath); | 28 external static _rename(String path, String newPath); |
| 29 external static List _list(String path, bool recursive); |
| 29 external static SendPort _newServicePort(); | 30 external static SendPort _newServicePort(); |
| 30 | 31 |
| 31 Future<bool> exists() { | 32 Future<bool> exists() { |
| 32 _ensureDirectoryService(); | 33 _ensureDirectoryService(); |
| 33 List request = new List(2); | 34 List request = new List(2); |
| 34 request[0] = EXISTS_REQUEST; | 35 request[0] = EXISTS_REQUEST; |
| 35 request[1] = _path; | 36 request[1] = _path; |
| 36 return _directoryService.call(request).transform((response) { | 37 return _directoryService.call(request).transform((response) { |
| 37 if (_isErrorResponse(response)) { | 38 if (_isErrorResponse(response)) { |
| 38 throw _exceptionOrErrorFromResponse(response, "Exists failed"); | 39 throw _exceptionOrErrorFromResponse(response, "Exists failed"); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (result is OSError) { | 223 if (result is OSError) { |
| 223 throw new DirectoryIOException("Rename failed", _path, result); | 224 throw new DirectoryIOException("Rename failed", _path, result); |
| 224 } | 225 } |
| 225 return new Directory(newPath); | 226 return new Directory(newPath); |
| 226 } | 227 } |
| 227 | 228 |
| 228 DirectoryLister list({bool recursive: false}) { | 229 DirectoryLister list({bool recursive: false}) { |
| 229 return new _DirectoryLister(_path, recursive); | 230 return new _DirectoryLister(_path, recursive); |
| 230 } | 231 } |
| 231 | 232 |
| 233 List listSync({bool recursive: false}) { |
| 234 if (_path is! String || recursive is! bool) { |
| 235 throw new ArgumentError(); |
| 236 } |
| 237 return _list(_path, recursive); |
| 238 } |
| 239 |
| 232 String get path => _path; | 240 String get path => _path; |
| 233 | 241 |
| 234 String toString() => "Directory: '$path'"; | 242 String toString() => "Directory: '$path'"; |
| 235 | 243 |
| 236 bool _isErrorResponse(response) { | 244 bool _isErrorResponse(response) { |
| 237 return response is List && response[0] != _SUCCESS_RESPONSE; | 245 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 238 } | 246 } |
| 239 | 247 |
| 240 _exceptionOrErrorFromResponse(response, String message) { | 248 _exceptionOrErrorFromResponse(response, String message) { |
| 241 assert(_isErrorResponse(response)); | 249 assert(_isErrorResponse(response)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } else { | 351 } else { |
| 344 throw e; | 352 throw e; |
| 345 } | 353 } |
| 346 } | 354 } |
| 347 | 355 |
| 348 Function _onDir; | 356 Function _onDir; |
| 349 Function _onFile; | 357 Function _onFile; |
| 350 Function _onDone; | 358 Function _onDone; |
| 351 Function _onError; | 359 Function _onError; |
| 352 } | 360 } |
| OLD | NEW |