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 extends FileSystemEntity implements Directory { | 7 class _Directory extends FileSystemEntity 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 11 matching lines...) Expand all Loading... |
22 throw new ArgumentError('${Error.safeToString(path)} ' | 22 throw new ArgumentError('${Error.safeToString(path)} ' |
23 'is not a String'); | 23 'is not a String'); |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 external static String _current(); | 27 external static String _current(); |
28 external static _setCurrent(path); | 28 external static _setCurrent(path); |
29 external static _createTemp(String template); | 29 external static _createTemp(String template); |
30 external static int _exists(String path); | 30 external static int _exists(String path); |
31 external static _create(String path); | 31 external static _create(String path); |
32 external static _delete(String path, bool recursive); | 32 external static _deleteNative(String path, bool recursive); |
33 external static _rename(String path, String newPath); | 33 external static _rename(String path, String newPath); |
34 external static List _list(String path, bool recursive, bool followLinks); | 34 external static List _list(String path, bool recursive, bool followLinks); |
35 external static SendPort _newServicePort(); | 35 external static SendPort _newServicePort(); |
36 | 36 |
37 static Directory get current => new _Directory(_current()); | 37 static Directory get current => new _Directory(_current()); |
38 | 38 |
39 static void set current(path) { | 39 static void set current(path) { |
40 if (path is Directory) path = path.path; | 40 if (path is Directory) path = path.path; |
41 var result = _setCurrent(path); | 41 var result = _setCurrent(path); |
42 if (result is ArgumentError) throw result; | 42 if (result is ArgumentError) throw result; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 Directory createTempSync() { | 176 Directory createTempSync() { |
177 var result = _createTemp(path); | 177 var result = _createTemp(path); |
178 if (result is OSError) { | 178 if (result is OSError) { |
179 throw new DirectoryException("Creation of temporary directory failed", | 179 throw new DirectoryException("Creation of temporary directory failed", |
180 path, | 180 path, |
181 result); | 181 result); |
182 } | 182 } |
183 return new Directory(result); | 183 return new Directory(result); |
184 } | 184 } |
185 | 185 |
186 Future<Directory> delete({recursive: false}) { | 186 Future<Directory> _delete({recursive: false}) { |
187 _ensureDirectoryService(); | 187 _ensureDirectoryService(); |
188 List request = new List(3); | 188 List request = new List(3); |
189 request[0] = DELETE_REQUEST; | 189 request[0] = DELETE_REQUEST; |
190 request[1] = path; | 190 request[1] = path; |
191 request[2] = recursive; | 191 request[2] = recursive; |
192 return _directoryService.call(request).then((response) { | 192 return _directoryService.call(request).then((response) { |
193 if (_isErrorResponse(response)) { | 193 if (_isErrorResponse(response)) { |
194 throw _exceptionOrErrorFromResponse(response, "Deletion failed"); | 194 throw _exceptionOrErrorFromResponse(response, "Deletion failed"); |
195 } | 195 } |
196 return this; | 196 return this; |
197 }); | 197 }); |
198 } | 198 } |
199 | 199 |
200 void deleteSync({recursive: false}) { | 200 void _deleteSync({recursive: false}) { |
201 var result = _delete(path, recursive); | 201 var result = _deleteNative(path, recursive); |
202 if (result is OSError) { | 202 if (result is OSError) { |
203 throw new DirectoryException("Deletion failed", path, result); | 203 throw new DirectoryException("Deletion failed", path, result); |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 Future<Directory> rename(String newPath) { | 207 Future<Directory> rename(String newPath) { |
208 _ensureDirectoryService(); | 208 _ensureDirectoryService(); |
209 List request = new List(3); | 209 List request = new List(3); |
210 request[0] = RENAME_REQUEST; | 210 request[0] = RENAME_REQUEST; |
211 request[1] = path; | 211 request[1] = path; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 controller.addError( | 399 controller.addError( |
400 new DirectoryException("Directory listing failed", | 400 new DirectoryException("Directory listing failed", |
401 errorPath, | 401 errorPath, |
402 err)); | 402 err)); |
403 } else { | 403 } else { |
404 controller.addError( | 404 controller.addError( |
405 new DirectoryException("Internal error")); | 405 new DirectoryException("Internal error")); |
406 } | 406 } |
407 } | 407 } |
408 } | 408 } |
OLD | NEW |