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

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

Issue 1974043002: Revert "Fix remaining strong-mode warnings and errors in dart:io." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « sdk/lib/io/data_transformer.dart ('k') | sdk/lib/io/file_impl.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 extends FileSystemEntity implements Directory { 7 class _Directory extends FileSystemEntity implements Directory {
8 final String path; 8 final String path;
9 9
10 _Directory(this.path) { 10 _Directory(this.path) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 return (result == 1); 66 return (result == 1);
67 } 67 }
68 68
69 Directory get absolute => new Directory(_absolutePath); 69 Directory get absolute => new Directory(_absolutePath);
70 70
71 Future<FileStat> stat() => FileStat.stat(path); 71 Future<FileStat> stat() => FileStat.stat(path);
72 72
73 FileStat statSync() => FileStat.statSync(path); 73 FileStat statSync() => FileStat.statSync(path);
74 74
75 // Compute the index of the first directory in the list that exists. If
76 // none of the directories exist dirsToCreate.length is returned.
77 Future<int> _computeExistingIndex(List dirsToCreate) {
78 var future;
79 var notFound = dirsToCreate.length;
80 for (var i = 0; i < dirsToCreate.length; i++) {
81 if (future == null) {
82 future = dirsToCreate[i].exists().then((e) => e ? i : notFound);
83 } else {
84 future = future.then((index) {
85 if (index != notFound) {
86 return new Future.value(index);
87 }
88 return dirsToCreate[i].exists().then((e) => e ? i : notFound);
89 });
90 }
91 }
92 if (future == null) {
93 return new Future.value(notFound);
94 } else {
95 return future;
96 }
97 }
98
75 Future<Directory> create({bool recursive: false}) { 99 Future<Directory> create({bool recursive: false}) {
76 if (recursive) { 100 if (recursive) {
77 return exists().then((exists) { 101 return exists().then((exists) {
78 if (exists) return this; 102 if (exists) return this;
79 if (path != parent.path) { 103 if (path != parent.path) {
80 return parent.create(recursive: true).then((_) { 104 return parent.create(recursive: true).then((_) {
81 return create(); 105 return create();
82 }); 106 });
83 } else { 107 } else {
84 return create(); 108 return create();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 273
250 static const int RESPONSE_TYPE = 0; 274 static const int RESPONSE_TYPE = 0;
251 static const int RESPONSE_PATH = 1; 275 static const int RESPONSE_PATH = 1;
252 static const int RESPONSE_COMPLETE = 1; 276 static const int RESPONSE_COMPLETE = 1;
253 static const int RESPONSE_ERROR = 2; 277 static const int RESPONSE_ERROR = 2;
254 278
255 final String path; 279 final String path;
256 final bool recursive; 280 final bool recursive;
257 final bool followLinks; 281 final bool followLinks;
258 282
259 StreamController<FileSystemEntity> controller; 283 StreamController controller;
260 bool canceled = false; 284 bool canceled = false;
261 bool nextRunning = false; 285 bool nextRunning = false;
262 bool closed = false; 286 bool closed = false;
263 _AsyncDirectoryListerOps _ops; 287 _AsyncDirectoryListerOps _ops;
264 Completer closeCompleter = new Completer(); 288 Completer closeCompleter = new Completer();
265 289
266 _AsyncDirectoryLister(this.path, this.recursive, this.followLinks) { 290 _AsyncDirectoryLister(this.path, this.recursive, this.followLinks) {
267 controller = new StreamController<FileSystemEntity>(onListen: onListen, 291 controller = new StreamController(onListen: onListen,
268 onResume: onResume, 292 onResume: onResume,
269 onCancel: onCancel, 293 onCancel: onCancel,
270 sync: true); 294 sync: true);
271 } 295 }
272 296
273 // Calling this function will increase the reference count on the native 297 // Calling this function will increase the reference count on the native
274 // object that implements the async directory lister operations. It should 298 // object that implements the async directory lister operations. It should
275 // only be called to pass the pointer to the IO Service, which will decrement 299 // only be called to pass the pointer to the IO Service, which will decrement
276 // the reference count when it is finished with it. 300 // the reference count when it is finished with it.
277 int _pointer() { 301 int _pointer() {
278 return (_ops == null) ? null : _ops.getPointer(); 302 return (_ops == null) ? null : _ops.getPointer();
279 } 303 }
280 304
281 Stream<FileSystemEntity> get stream => controller.stream; 305 Stream get stream => controller.stream;
282 306
283 void onListen() { 307 void onListen() {
284 _IOService._dispatch(_DIRECTORY_LIST_START, [path, recursive, followLinks]) 308 _IOService._dispatch(_DIRECTORY_LIST_START, [path, recursive, followLinks])
285 .then((response) { 309 .then((response) {
286 if (response is int) { 310 if (response is int) {
287 _ops = new _AsyncDirectoryListerOps(response); 311 _ops = new _AsyncDirectoryListerOps(response);
288 next(); 312 next();
289 } else if (response is Error) { 313 } else if (response is Error) {
290 controller.addError(response, response.stackTrace); 314 controller.addError(response, response.stackTrace);
291 close(); 315 close();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 controller.addError( 419 controller.addError(
396 new FileSystemException("Directory listing failed", 420 new FileSystemException("Directory listing failed",
397 errorPath, 421 errorPath,
398 err)); 422 err));
399 } else { 423 } else {
400 controller.addError( 424 controller.addError(
401 new FileSystemException("Internal error")); 425 new FileSystemException("Internal error"));
402 } 426 }
403 } 427 }
404 } 428 }
OLDNEW
« no previous file with comments | « sdk/lib/io/data_transformer.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698