Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Side by Side Diff: sdk/lib/io/directory_impl.dart

Issue 13896034: Add the ability to change the working directory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed tests Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/directory.dart ('k') | tests/standalone/io/directory_chdir_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
11 static const CREATE_TEMP_REQUEST = 3; 11 static const CREATE_TEMP_REQUEST = 3;
12 static const LIST_REQUEST = 4; 12 static const LIST_REQUEST = 4;
13 static const RENAME_REQUEST = 5; 13 static const RENAME_REQUEST = 5;
14 14
15 static const SUCCESS_RESPONSE = 0; 15 static const SUCCESS_RESPONSE = 0;
16 static const ILLEGAL_ARGUMENT_RESPONSE = 1; 16 static const ILLEGAL_ARGUMENT_RESPONSE = 1;
17 static const OSERROR_RESPONSE = 2; 17 static const OSERROR_RESPONSE = 2;
18 18
19 _Directory(String this._path); 19 _Directory(String this._path);
20 _Directory.fromPath(Path path) : this(path.toNativePath()); 20 _Directory.fromPath(Path path) : this(path.toNativePath());
21 _Directory.current() : this(_current());
22 21
23 external static String _current(); 22 external static String _current();
23 external static _setCurrent(String path);
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, bool followLinks); 29 external static List _list(String path, bool recursive, bool followLinks);
30 external static SendPort _newServicePort(); 30 external static SendPort _newServicePort();
31 31
32 static Directory get current => new _Directory(_current());
33
34 static void set current(path) {
35 if (path is Directory) path = path.path;
36 var result = _setCurrent(path);
37 if (result is ArgumentError) throw result;
38 if (result is OSError) {
39 throw new DirectoryIOException(
40 "Setting current working directory failed", path, result);
41 }
42 }
43
32 Future<bool> exists() { 44 Future<bool> exists() {
33 _ensureDirectoryService(); 45 _ensureDirectoryService();
34 List request = new List(2); 46 List request = new List(2);
35 request[0] = EXISTS_REQUEST; 47 request[0] = EXISTS_REQUEST;
36 request[1] = _path; 48 request[1] = _path;
37 return _directoryService.call(request).then((response) { 49 return _directoryService.call(request).then((response) {
38 if (_isErrorResponse(response)) { 50 if (_isErrorResponse(response)) {
39 throw _exceptionOrErrorFromResponse(response, "Exists failed"); 51 throw _exceptionOrErrorFromResponse(response, "Exists failed");
40 } 52 }
41 return response == 1; 53 return response == 1;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 335
324 void _ensureDirectoryService() { 336 void _ensureDirectoryService() {
325 if (_directoryService == null) { 337 if (_directoryService == null) {
326 _directoryService = _newServicePort(); 338 _directoryService = _newServicePort();
327 } 339 }
328 } 340 }
329 341
330 final String _path; 342 final String _path;
331 SendPort _directoryService; 343 SendPort _directoryService;
332 } 344 }
OLDNEW
« no previous file with comments | « sdk/lib/io/directory.dart ('k') | tests/standalone/io/directory_chdir_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698