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 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 bool _list(String dir, | 23 bool _list(String dir, |
24 bool recursive, | 24 bool recursive, |
25 SendPort dirPort, | 25 SendPort dirPort, |
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 _DirectoryCreateTempIsolate extends Isolate { | |
33 | |
34 _DirectoryCreateTempIsolate() : super.heavy(); | |
35 | |
36 void main() { | |
37 port.receive((path, replyTo) { | |
38 if (path == '') path = '/tmp/darttmpdirXXXXXX'; | |
Mads Ager (google)
2011/11/18 09:50:45
You should add a comment about this default behavi
Bill Hesse
2011/11/21 15:48:41
Moved to .cc file.
| |
39 | |
40 // Call function to get file name | |
41 String result = _createTemp(path); | |
42 var message = {'success': (result != ''), 'directoryName': result}; | |
Mads Ager (google)
2011/11/18 09:50:45
Do this in the caller? Just do replyTo.send(_creat
Bill Hesse
2011/11/21 15:48:41
Done.
| |
43 replyTo.send(message); | |
44 port.close(); | |
45 }); | |
46 } | |
47 | |
48 String _createTemp(String template) native "Directory_CreateTemp"; | |
49 } | |
50 | |
51 | |
32 class _Directory implements Directory { | 52 class _Directory implements Directory { |
33 | 53 |
34 _Directory(String this._path); | 54 _Directory(String this._path); |
35 | 55 |
36 bool existsSync() { | 56 bool existsSync() { |
37 int exists = _exists(_path); | 57 int exists = _exists(_path); |
38 if (exists < 0) { | 58 if (exists < 0) { |
39 throw new DirectoryException("Diretory exists test failed: $_path"); | 59 throw new DirectoryException("Diretory exists test failed: $_path"); |
40 } | 60 } |
41 return (exists == 1); | 61 return (exists == 1); |
42 } | 62 } |
43 | 63 |
44 void createSync() { | 64 void createSync() { |
45 if (!_create(_path)) { | 65 if (!_create(_path)) { |
46 throw new DirectoryException("Directory creation failed: $_path"); | 66 throw new DirectoryException("Directory creation failed: $_path"); |
47 } | 67 } |
48 } | 68 } |
49 | 69 |
70 void createTemp(void createdHandler(Directory tempDir)) { | |
71 new _DirectoryCreateTempIsolate().spawn().then((port) { | |
72 port.call(_path).receive((result, ignored) { | |
73 if (result['success']) { | |
74 // Create new Directory with returned file name. | |
75 Directory tempDir = new Directory(result['directoryName']); | |
76 tempDir.dirHandler = _dirHandler; | |
Mads Ager (google)
2011/11/18 09:50:45
This is subtle, why do you transfer the handlers?
Bill Hesse
2011/11/21 15:48:41
All this is removed, and we do not create a new Di
| |
77 tempDir.fileHandler = _fileHandler; | |
78 tempDir.doneHandler = _doneHandler; | |
79 tempDir.errorHandler = _errorHandler; | |
80 createdHandler(tempDir); | |
81 } else { | |
82 // Report error | |
83 } | |
84 }); | |
85 }); | |
86 } | |
87 | |
50 void deleteSync() { | 88 void deleteSync() { |
51 if (!_delete(_path)) { | 89 if (!_delete(_path)) { |
52 throw new DirectoryException("Directory deletion failed: $_path"); | 90 throw new DirectoryException("Directory deletion failed: $_path"); |
53 } | 91 } |
54 } | 92 } |
55 | 93 |
56 void list([bool recursive = false]) { | 94 void list([bool recursive = false]) { |
57 new _DirectoryListingIsolate().spawn().then((port) { | 95 new _DirectoryListingIsolate().spawn().then((port) { |
58 // Build a map of parameters to the directory listing isolate. | 96 // Build a map of parameters to the directory listing isolate. |
59 Map listingParameters = new Map(); | 97 Map listingParameters = new Map(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 bool _create(String path) native "Directory_Create"; | 183 bool _create(String path) native "Directory_Create"; |
146 bool _delete(String path) native "Directory_Delete"; | 184 bool _delete(String path) native "Directory_Delete"; |
147 | 185 |
148 var _dirHandler; | 186 var _dirHandler; |
149 var _fileHandler; | 187 var _fileHandler; |
150 var _doneHandler; | 188 var _doneHandler; |
151 var _errorHandler; | 189 var _errorHandler; |
152 | 190 |
153 String _path; | 191 String _path; |
154 } | 192 } |
OLD | NEW |