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

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

Issue 23054008: Remove the Path class from dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed first round of review comments Created 7 years, 4 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
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_START_REQUEST = 4; 12 static const LIST_START_REQUEST = 4;
13 static const LIST_NEXT_REQUEST = 5; 13 static const LIST_NEXT_REQUEST = 5;
14 static const LIST_STOP_REQUEST = 6; 14 static const LIST_STOP_REQUEST = 6;
15 static const RENAME_REQUEST = 7; 15 static const RENAME_REQUEST = 7;
16 16
17 final String path; 17 final String path;
18 SendPort _directoryService; 18 SendPort _directoryService;
19 19
20 _Directory(String this.path) { 20 _Directory(String this.path) {
21 if (path is! String) { 21 if (path is! String) {
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 _Directory.fromPath(Path path) : this(path.toNativePath());
28
29 external static String _current(); 27 external static String _current();
30 external static _setCurrent(path); 28 external static _setCurrent(path);
31 external static _createTemp(String template); 29 external static _createTemp(String template);
32 external static int _exists(String path); 30 external static int _exists(String path);
33 external static _create(String path); 31 external static _create(String path);
34 external static _delete(String path, bool recursive); 32 external static _delete(String path, bool recursive);
35 external static _rename(String path, String newPath); 33 external static _rename(String path, String newPath);
36 external static List _list(String path, bool recursive, bool followLinks); 34 external static List _list(String path, bool recursive, bool followLinks);
37 external static SendPort _newServicePort(); 35 external static SendPort _newServicePort();
38 36
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 89 }
92 } 90 }
93 if (future == null) { 91 if (future == null) {
94 return new Future.value(notFound); 92 return new Future.value(notFound);
95 } else { 93 } else {
96 return future; 94 return future;
97 } 95 }
98 } 96 }
99 97
100 Future<Directory> createRecursively() { 98 Future<Directory> createRecursively() {
101 var path = new Path(this.path); 99 var path = new _Path(this.path);
102 var dirsToCreate = []; 100 var dirsToCreate = [];
103 var terminator = path.isAbsolute ? '/' : ''; 101 var terminator = path.isAbsolute ? '/' : '';
104 while (path.toString() != terminator) { 102 while (path.toString() != terminator) {
105 dirsToCreate.add(new Directory.fromPath(path)); 103 dirsToCreate.add(new Directory(path.toNativePath()));
106 path = path.directoryPath; 104 path = path.directoryPath;
107 } 105 }
108 return _computeExistingIndex(dirsToCreate).then((index) { 106 return _computeExistingIndex(dirsToCreate).then((index) {
109 var future; 107 var future;
110 for (var i = index - 1; i >= 0 ; i--) { 108 for (var i = index - 1; i >= 0 ; i--) {
111 if (future == null) { 109 if (future == null) {
112 future = dirsToCreate[i].create(); 110 future = dirsToCreate[i].create();
113 } else { 111 } else {
114 future = future.then((_) { 112 future = future.then((_) {
115 return dirsToCreate[i].create(); 113 return dirsToCreate[i].create();
(...skipping 16 matching lines...) Expand all
132 request[1] = path; 130 request[1] = path;
133 return _directoryService.call(request).then((response) { 131 return _directoryService.call(request).then((response) {
134 if (_isErrorResponse(response)) { 132 if (_isErrorResponse(response)) {
135 throw _exceptionOrErrorFromResponse(response, "Creation failed"); 133 throw _exceptionOrErrorFromResponse(response, "Creation failed");
136 } 134 }
137 return this; 135 return this;
138 }); 136 });
139 } 137 }
140 138
141 void createRecursivelySync() { 139 void createRecursivelySync() {
142 var path = new Path(this.path); 140 var path = new _Path(this.path);
143 var dirsToCreate = []; 141 var dirsToCreate = [];
144 var terminator = path.isAbsolute ? '/' : ''; 142 var terminator = path.isAbsolute ? '/' : '';
145 while (path.toString() != terminator) { 143 while (path.toString() != terminator) {
146 var dir = new Directory.fromPath(path); 144 var dir = new Directory(path.toNativePath());
147 if (dir.existsSync()) break; 145 if (dir.existsSync()) break;
148 dirsToCreate.add(dir); 146 dirsToCreate.add(dir);
149 path = path.directoryPath; 147 path = path.directoryPath;
150 } 148 }
151 for (var i = dirsToCreate.length - 1; i >= 0; i--) { 149 for (var i = dirsToCreate.length - 1; i >= 0; i--) {
152 dirsToCreate[i].createSync(); 150 dirsToCreate[i].createSync();
153 } 151 }
154 } 152 }
155 153
156 void createSync({recursive: false}) { 154 void createSync({recursive: false}) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 controller.addError( 412 controller.addError(
415 new DirectoryException("Directory listing failed", 413 new DirectoryException("Directory listing failed",
416 errorPath, 414 errorPath,
417 err)); 415 err));
418 } else { 416 } else {
419 controller.addError( 417 controller.addError(
420 new DirectoryException("Internal error")); 418 new DirectoryException("Internal error"));
421 } 419 }
422 } 420 }
423 } 421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698