| 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 _DirectoryListingIsolate extends Isolate { | 6 class _DirectoryListingIsolate extends Isolate { |
| 7 | 7 |
| 8 _DirectoryListingIsolate() : super.heavy(); | 8 _DirectoryListingIsolate() : super.heavy(); |
| 9 | 9 |
| 10 void main() { | 10 void main() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 SendPort filePort, | 26 SendPort filePort, |
| 27 SendPort donePort, | 27 SendPort donePort, |
| 28 SendPort errorPort) native "Directory_List"; | 28 SendPort errorPort) native "Directory_List"; |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 class _Directory implements Directory { | 32 class _Directory implements Directory { |
| 33 | 33 |
| 34 _Directory(String this._path); | 34 _Directory(String this._path); |
| 35 | 35 |
| 36 bool exists() { | 36 bool existsSync() { |
| 37 int exists = _exists(_path); | 37 int exists = _exists(_path); |
| 38 if (exists < 0) { | 38 if (exists < 0) { |
| 39 // TODO(ager): Supply a better error message. | 39 // TODO(ager): Supply a better error message. |
| 40 throw new DirectoryException("Diretory exists test failed: $_path"); | 40 throw new DirectoryException("Diretory exists test failed: $_path"); |
| 41 } | 41 } |
| 42 return (exists == 1); | 42 return (exists == 1); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void create() { | 45 void createSync() { |
| 46 if (!_create(_path)) { | 46 if (!_create(_path)) { |
| 47 // TODO(ager): Supply a better error message. | 47 // TODO(ager): Supply a better error message. |
| 48 throw new DirectoryException("Directory creation failed: $_path"); | 48 throw new DirectoryException("Directory creation failed: $_path"); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 void delete() { | 52 void deleteSync() { |
| 53 if (!_delete(_path)) { | 53 if (!_delete(_path)) { |
| 54 // TODO(ager): Supply a better error message. | 54 // TODO(ager): Supply a better error message. |
| 55 throw new DirectoryException("Directory deletion failed: $_path"); | 55 throw new DirectoryException("Directory deletion failed: $_path"); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void list([bool recursive = false]) { | 59 void list([bool recursive = false]) { |
| 60 new _DirectoryListingIsolate().spawn().then((port) { | 60 new _DirectoryListingIsolate().spawn().then((port) { |
| 61 // Build a map of parameters to the directory listing isolate. | 61 // Build a map of parameters to the directory listing isolate. |
| 62 Map listingParameters = new Map(); | 62 Map listingParameters = new Map(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 _closePort(dirPort); | 113 _closePort(dirPort); |
| 114 _closePort(filePort); | 114 _closePort(filePort); |
| 115 _closePort(closePortsPort); | 115 _closePort(closePortsPort); |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 // Send the listing parameters to the isolate. | 118 // Send the listing parameters to the isolate. |
| 119 port.send(listingParameters, closePortsPort.toSendPort()); | 119 port.send(listingParameters, closePortsPort.toSendPort()); |
| 120 }); | 120 }); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void setDirHandler(void dirHandler(String dir)) { | 123 void set dirHandler(void dirHandler(String dir)) { |
| 124 _dirHandler = dirHandler; | 124 _dirHandler = dirHandler; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void setFileHandler(void fileHandler(String file)) { | 127 void set fileHandler(void fileHandler(String file)) { |
| 128 _fileHandler = fileHandler; | 128 _fileHandler = fileHandler; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void setDoneHandler(void doneHandler(bool completed)) { | 131 void set doneHandler(void doneHandler(bool completed)) { |
| 132 _doneHandler = doneHandler; | 132 _doneHandler = doneHandler; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void setErrorHandler(void errorHandler(String error)) { | 135 void set errorHandler(void errorHandler(String error)) { |
| 136 _errorHandler = errorHandler; | 136 _errorHandler = errorHandler; |
| 137 } | 137 } |
| 138 | 138 |
| 139 void _closePort(ReceivePort port) { | 139 void _closePort(ReceivePort port) { |
| 140 if (port !== null) { | 140 if (port !== null) { |
| 141 port.close(); | 141 port.close(); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 String get path() { return _path; } | 145 String get path() { return _path; } |
| 146 | 146 |
| 147 int _exists(String path) native "Directory_Exists"; | 147 int _exists(String path) native "Directory_Exists"; |
| 148 bool _create(String path) native "Directory_Create"; | 148 bool _create(String path) native "Directory_Create"; |
| 149 bool _delete(String path) native "Directory_Delete"; | 149 bool _delete(String path) native "Directory_Delete"; |
| 150 | 150 |
| 151 var _dirHandler; | 151 var _dirHandler; |
| 152 var _fileHandler; | 152 var _fileHandler; |
| 153 var _doneHandler; | 153 var _doneHandler; |
| 154 var _errorHandler; | 154 var _errorHandler; |
| 155 | 155 |
| 156 String _path; | 156 String _path; |
| 157 } | 157 } |
| OLD | NEW |