Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { | 6 class DirectoryException { |
| 7 String toString() { return "DirectoryException: $message"; } | |
| 7 const DirectoryException(String this.message); | 8 const DirectoryException(String this.message); |
| 8 final String message; | 9 final String message; |
| 9 } | 10 } |
| 10 | 11 |
| 11 | 12 |
| 12 class _DirectoryListingIsolate extends Isolate { | 13 class _DirectoryListingIsolate extends Isolate { |
| 13 | 14 |
| 14 _DirectoryListingIsolate() : super.heavy(); | 15 _DirectoryListingIsolate() : super.heavy(); |
| 15 | 16 |
| 16 void main() { | 17 void main() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 29 bool recursive, | 30 bool recursive, |
| 30 SendPort dirPort, | 31 SendPort dirPort, |
| 31 SendPort filePort, | 32 SendPort filePort, |
| 32 SendPort donePort, | 33 SendPort donePort, |
| 33 SendPort errorPort) native "Directory_List"; | 34 SendPort errorPort) native "Directory_List"; |
| 34 } | 35 } |
| 35 | 36 |
| 36 | 37 |
| 37 class _Directory implements Directory { | 38 class _Directory implements Directory { |
| 38 | 39 |
| 39 _Directory(String this._dir); | 40 _Directory(String this._path); |
| 41 | |
| 42 bool exists() { | |
| 43 int exists = _exists(_path); | |
|
Søren Gjesse
2011/10/14 11:44:14
Should we provide errno/strerrno information here
Mads Ager (google)
2011/10/14 12:22:54
Yes, we should. Added a TODO to all of the new met
| |
| 44 if (exists < 0) { | |
| 45 throw new DirectoryException("Diretory exists test failed: $_path"); | |
| 46 } | |
| 47 return (exists == 1); | |
| 48 } | |
| 49 | |
| 50 void create() { | |
| 51 if (!_create(_path)) { | |
| 52 throw new DirectoryException("Directory creation failed: $_path"); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void delete() { | |
| 57 if (!_delete(_path)) { | |
| 58 throw new DirectoryException("Directory deletion failed: $_path"); | |
| 59 } | |
| 60 } | |
| 40 | 61 |
| 41 void list([bool recursive = false]) { | 62 void list([bool recursive = false]) { |
| 42 new _DirectoryListingIsolate().spawn().then((port) { | 63 new _DirectoryListingIsolate().spawn().then((port) { |
| 43 // Build a map of parameters to the directory listing isolate. | 64 // Build a map of parameters to the directory listing isolate. |
| 44 Map listingParameters = new Map(); | 65 Map listingParameters = new Map(); |
| 45 listingParameters['dir'] = _dir; | 66 listingParameters['dir'] = _path; |
| 46 listingParameters['recursive'] = recursive; | 67 listingParameters['recursive'] = recursive; |
| 47 | 68 |
| 48 // Setup ports to receive messages from listing. | 69 // Setup ports to receive messages from listing. |
| 49 // TODO(ager): Do not explicitly transform to send ports when | 70 // TODO(ager): Do not explicitly transform to send ports when |
| 50 // implicit conversions are implemented. | 71 // implicit conversions are implemented. |
| 51 ReceivePort dirPort; | 72 ReceivePort dirPort; |
| 52 ReceivePort filePort; | 73 ReceivePort filePort; |
| 53 ReceivePort donePort; | 74 ReceivePort donePort; |
| 54 ReceivePort errorPort; | 75 ReceivePort errorPort; |
| 55 if (_dirHandler !== null) { | 76 if (_dirHandler !== null) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 void setErrorHandler(void errorHandler(String error)) { | 132 void setErrorHandler(void errorHandler(String error)) { |
| 112 _errorHandler = errorHandler; | 133 _errorHandler = errorHandler; |
| 113 } | 134 } |
| 114 | 135 |
| 115 void _closePort(ReceivePort port) { | 136 void _closePort(ReceivePort port) { |
| 116 if (port !== null) { | 137 if (port !== null) { |
| 117 port.close(); | 138 port.close(); |
| 118 } | 139 } |
| 119 } | 140 } |
| 120 | 141 |
| 142 String get path() { return _path; } | |
| 143 | |
| 144 bool _exists(String path) native "Directory_Exists"; | |
| 145 bool _create(String path) native "Directory_Create"; | |
| 146 bool _delete(String path) native "Directory_Delete"; | |
| 147 | |
| 121 var _dirHandler; | 148 var _dirHandler; |
| 122 var _fileHandler; | 149 var _fileHandler; |
| 123 var _doneHandler; | 150 var _doneHandler; |
| 124 var _errorHandler; | 151 var _errorHandler; |
| 125 | 152 |
| 126 String _dir; | 153 String _path; |
| 127 } | 154 } |
| OLD | NEW |