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; |
(...skipping 13 matching lines...) Expand all Loading... |
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 List _list(String path, bool recursive); |
30 external static SendPort _newServicePort(); | 30 external static SendPort _newServicePort(); |
31 | 31 |
32 Future<bool> exists() { | 32 Future<bool> exists() { |
33 _ensureDirectoryService(); | 33 _ensureDirectoryService(); |
34 List request = new List.fixedLength(2); | 34 List request = new List(2); |
35 request[0] = EXISTS_REQUEST; | 35 request[0] = EXISTS_REQUEST; |
36 request[1] = _path; | 36 request[1] = _path; |
37 return _directoryService.call(request).then((response) { | 37 return _directoryService.call(request).then((response) { |
38 if (_isErrorResponse(response)) { | 38 if (_isErrorResponse(response)) { |
39 throw _exceptionOrErrorFromResponse(response, "Exists failed"); | 39 throw _exceptionOrErrorFromResponse(response, "Exists failed"); |
40 } | 40 } |
41 return response == 1; | 41 return response == 1; |
42 }); | 42 }); |
43 } | 43 } |
44 | 44 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 return new Future.immediate(this); | 103 return new Future.immediate(this); |
104 } else { | 104 } else { |
105 return future.then((_) => this); | 105 return future.then((_) => this); |
106 } | 106 } |
107 }); | 107 }); |
108 } | 108 } |
109 | 109 |
110 Future<Directory> create({recursive: false}) { | 110 Future<Directory> create({recursive: false}) { |
111 if (recursive) return createRecursively(); | 111 if (recursive) return createRecursively(); |
112 _ensureDirectoryService(); | 112 _ensureDirectoryService(); |
113 List request = new List.fixedLength(2); | 113 List request = new List(2); |
114 request[0] = CREATE_REQUEST; | 114 request[0] = CREATE_REQUEST; |
115 request[1] = _path; | 115 request[1] = _path; |
116 return _directoryService.call(request).then((response) { | 116 return _directoryService.call(request).then((response) { |
117 if (_isErrorResponse(response)) { | 117 if (_isErrorResponse(response)) { |
118 throw _exceptionOrErrorFromResponse(response, "Creation failed"); | 118 throw _exceptionOrErrorFromResponse(response, "Creation failed"); |
119 } | 119 } |
120 return this; | 120 return this; |
121 }); | 121 }); |
122 } | 122 } |
123 | 123 |
(...skipping 18 matching lines...) Expand all Loading... |
142 } | 142 } |
143 if (recursive) return createRecursivelySync(); | 143 if (recursive) return createRecursivelySync(); |
144 var result = _create(_path); | 144 var result = _create(_path); |
145 if (result is OSError) { | 145 if (result is OSError) { |
146 throw new DirectoryIOException("Creation failed", _path, result); | 146 throw new DirectoryIOException("Creation failed", _path, result); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 Future<Directory> createTemp() { | 150 Future<Directory> createTemp() { |
151 _ensureDirectoryService(); | 151 _ensureDirectoryService(); |
152 List request = new List.fixedLength(2); | 152 List request = new List(2); |
153 request[0] = CREATE_TEMP_REQUEST; | 153 request[0] = CREATE_TEMP_REQUEST; |
154 request[1] = _path; | 154 request[1] = _path; |
155 return _directoryService.call(request).then((response) { | 155 return _directoryService.call(request).then((response) { |
156 if (_isErrorResponse(response)) { | 156 if (_isErrorResponse(response)) { |
157 throw _exceptionOrErrorFromResponse(response, | 157 throw _exceptionOrErrorFromResponse(response, |
158 "Creation of temporary directory failed"); | 158 "Creation of temporary directory failed"); |
159 } | 159 } |
160 return new Directory(response); | 160 return new Directory(response); |
161 }); | 161 }); |
162 } | 162 } |
163 | 163 |
164 Directory createTempSync() { | 164 Directory createTempSync() { |
165 if (_path is !String) { | 165 if (_path is !String) { |
166 throw new ArgumentError(); | 166 throw new ArgumentError(); |
167 } | 167 } |
168 var result = _createTemp(path); | 168 var result = _createTemp(path); |
169 if (result is OSError) { | 169 if (result is OSError) { |
170 throw new DirectoryIOException("Creation of temporary directory failed", | 170 throw new DirectoryIOException("Creation of temporary directory failed", |
171 _path, | 171 _path, |
172 result); | 172 result); |
173 } | 173 } |
174 return new Directory(result); | 174 return new Directory(result); |
175 } | 175 } |
176 | 176 |
177 Future<Directory> _deleteHelper(bool recursive, String errorMsg) { | 177 Future<Directory> _deleteHelper(bool recursive, String errorMsg) { |
178 } | 178 } |
179 | 179 |
180 Future<Directory> delete({recursive: false}) { | 180 Future<Directory> delete({recursive: false}) { |
181 _ensureDirectoryService(); | 181 _ensureDirectoryService(); |
182 List request = new List.fixedLength(3); | 182 List request = new List(3); |
183 request[0] = DELETE_REQUEST; | 183 request[0] = DELETE_REQUEST; |
184 request[1] = _path; | 184 request[1] = _path; |
185 request[2] = recursive; | 185 request[2] = recursive; |
186 return _directoryService.call(request).then((response) { | 186 return _directoryService.call(request).then((response) { |
187 if (_isErrorResponse(response)) { | 187 if (_isErrorResponse(response)) { |
188 throw _exceptionOrErrorFromResponse(response, "Deletion failed"); | 188 throw _exceptionOrErrorFromResponse(response, "Deletion failed"); |
189 } | 189 } |
190 return this; | 190 return this; |
191 }); | 191 }); |
192 } | 192 } |
193 | 193 |
194 void deleteSync({recursive: false}) { | 194 void deleteSync({recursive: false}) { |
195 if (_path is !String) { | 195 if (_path is !String) { |
196 throw new ArgumentError(); | 196 throw new ArgumentError(); |
197 } | 197 } |
198 var result = _delete(_path, recursive); | 198 var result = _delete(_path, recursive); |
199 if (result is OSError) { | 199 if (result is OSError) { |
200 throw new DirectoryIOException("Deletion failed", _path, result); | 200 throw new DirectoryIOException("Deletion failed", _path, result); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 Future<Directory> rename(String newPath) { | 204 Future<Directory> rename(String newPath) { |
205 _ensureDirectoryService(); | 205 _ensureDirectoryService(); |
206 List request = new List.fixedLength(3); | 206 List request = new List(3); |
207 request[0] = RENAME_REQUEST; | 207 request[0] = RENAME_REQUEST; |
208 request[1] = _path; | 208 request[1] = _path; |
209 request[2] = newPath; | 209 request[2] = newPath; |
210 return _directoryService.call(request).then((response) { | 210 return _directoryService.call(request).then((response) { |
211 if (_isErrorResponse(response)) { | 211 if (_isErrorResponse(response)) { |
212 throw _exceptionOrErrorFromResponse(response, "Rename failed"); | 212 throw _exceptionOrErrorFromResponse(response, "Rename failed"); |
213 } | 213 } |
214 return new Directory(newPath); | 214 return new Directory(newPath); |
215 }); | 215 }); |
216 } | 216 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 318 |
319 void _ensureDirectoryService() { | 319 void _ensureDirectoryService() { |
320 if (_directoryService == null) { | 320 if (_directoryService == null) { |
321 _directoryService = _newServicePort(); | 321 _directoryService = _newServicePort(); |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 final String _path; | 325 final String _path; |
326 SendPort _directoryService; | 326 SendPort _directoryService; |
327 } | 327 } |
OLD | NEW |