| 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 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 class _DirectoryCreateTempIsolate extends Isolate { | 32 class _DirectoryCreateTempIsolate extends Isolate { |
| 33 | 33 |
| 34 _DirectoryCreateTempIsolate() : super.heavy(); | 34 _DirectoryCreateTempIsolate() : super.heavy(); |
| 35 | 35 |
| 36 void main() { | 36 void main() { |
| 37 port.receive((path, replyTo) { | 37 port.receive((path, replyTo) { |
| 38 // Call function to get file name | 38 // Call function to get file name |
| 39 replyTo.send(_createTemp(path, (Math.random() * 0x8000000).toInt())); | 39 replyTo.send(_Directory._createTemp(path, (Math.random() * 0x8000000).toIn
t())); |
| 40 port.close(); | 40 port.close(); |
| 41 }); | 41 }); |
| 42 } | 42 } |
| 43 | |
| 44 String _createTemp(String template, int num) native "Directory_CreateTemp"; | |
| 45 } | 43 } |
| 46 | 44 |
| 47 | 45 |
| 48 class _Directory implements Directory { | 46 class _Directory implements Directory { |
| 49 | 47 |
| 50 _Directory(String this._path); | 48 _Directory(String this._path); |
| 51 | 49 |
| 50 static String _createTemp(String template, int num) native "Directory_CreateTe
mp"; |
| 51 |
| 52 bool existsSync() { | 52 bool existsSync() { |
| 53 int exists = _exists(_path); | 53 int exists = _exists(_path); |
| 54 if (exists < 0) { | 54 if (exists < 0) { |
| 55 throw new DirectoryException("Diretory exists test failed: $_path"); | 55 throw new DirectoryException("Diretory exists test failed: $_path"); |
| 56 } | 56 } |
| 57 return (exists == 1); | 57 return (exists == 1); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void createSync() { | 60 void createSync() { |
| 61 if (!_create(_path)) { | 61 if (!_create(_path)) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 } | 73 } |
| 74 } else { | 74 } else { |
| 75 if (_errorHandler !== null) { | 75 if (_errorHandler !== null) { |
| 76 _errorHandler("Could not create temporary directory: $_path"); | 76 _errorHandler("Could not create temporary directory: $_path"); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 }); | 79 }); |
| 80 }); | 80 }); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void createTempSync() { |
| 84 var result = _createTemp(path, (Math.random() * 0x8000000).toInt()); |
| 85 if (result != '') { |
| 86 _path = result; |
| 87 } else { |
| 88 throw "createTempSync failed"; |
| 89 } |
| 90 } |
| 91 |
| 83 void deleteSync() { | 92 void deleteSync() { |
| 84 if (!_delete(_path)) { | 93 if (!_delete(_path)) { |
| 85 throw new DirectoryException("Directory deletion failed: $_path"); | 94 throw new DirectoryException("Directory deletion failed: $_path"); |
| 86 } | 95 } |
| 87 } | 96 } |
| 88 | 97 |
| 89 void list([bool recursive = false]) { | 98 void list([bool recursive = false]) { |
| 90 new _DirectoryListingIsolate().spawn().then((port) { | 99 new _DirectoryListingIsolate().spawn().then((port) { |
| 91 // Build a map of parameters to the directory listing isolate. | 100 // Build a map of parameters to the directory listing isolate. |
| 92 Map listingParameters = new Map(); | 101 Map listingParameters = new Map(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 bool _delete(String path) native "Directory_Delete"; | 192 bool _delete(String path) native "Directory_Delete"; |
| 184 | 193 |
| 185 var _dirHandler; | 194 var _dirHandler; |
| 186 var _fileHandler; | 195 var _fileHandler; |
| 187 var _doneHandler; | 196 var _doneHandler; |
| 188 var _createTempHandler; | 197 var _createTempHandler; |
| 189 var _errorHandler; | 198 var _errorHandler; |
| 190 | 199 |
| 191 String _path; | 200 String _path; |
| 192 } | 201 } |
| OLD | NEW |