| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 if (_path is !String) { | 45 if (_path is !String) { |
| 46 throw new ArgumentError(); | 46 throw new ArgumentError(); |
| 47 } | 47 } |
| 48 var result = _exists(_path); | 48 var result = _exists(_path); |
| 49 if (result is OSError) { | 49 if (result is OSError) { |
| 50 throw new DirectoryIOException("Exists failed", _path, result); | 50 throw new DirectoryIOException("Exists failed", _path, result); |
| 51 } | 51 } |
| 52 return (result == 1); | 52 return (result == 1); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Compute the index of the first directory in the list that exists. If |
| 56 // none of the directories exist dirsToCreate.length is returned. |
| 55 Future<int> _computeExistingIndex(List dirsToCreate) { | 57 Future<int> _computeExistingIndex(List dirsToCreate) { |
| 56 var future; | 58 var future; |
| 59 var notFound = dirsToCreate.length; |
| 57 for (var i = 0; i < dirsToCreate.length; i++) { | 60 for (var i = 0; i < dirsToCreate.length; i++) { |
| 58 if (future == null) { | 61 if (future == null) { |
| 59 future = dirsToCreate[i].exists().transform((e) => e ? i : -1); | 62 future = dirsToCreate[i].exists().transform((e) => e ? i : notFound); |
| 60 } else { | 63 } else { |
| 61 future = future.chain((index) { | 64 future = future.chain((index) { |
| 62 if (index != -1) { | 65 if (index != notFound) { |
| 63 return new Future.immediate(index); | 66 return new Future.immediate(index); |
| 64 } | 67 } |
| 65 return dirsToCreate[i].exists().transform((e) => e ? i : -1); | 68 return dirsToCreate[i].exists().transform((e) => e ? i : notFound); |
| 66 }); | 69 }); |
| 67 } | 70 } |
| 68 } | 71 } |
| 69 if (future == null) { | 72 if (future == null) { |
| 70 return new Future.immediate(-1); | 73 return new Future.immediate(notFound); |
| 71 } else { | 74 } else { |
| 72 return future; | 75 return future; |
| 73 } | 76 } |
| 74 } | 77 } |
| 75 | 78 |
| 76 Future<Directory> createRecursively() { | 79 Future<Directory> createRecursively() { |
| 77 if (_path is !String) { | 80 if (_path is !String) { |
| 78 throw new ArgumentError(); | 81 throw new ArgumentError(); |
| 79 } | 82 } |
| 80 var path = new Path.fromNative(_path); | 83 var path = new Path.fromNative(_path); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } else { | 343 } else { |
| 341 throw e; | 344 throw e; |
| 342 } | 345 } |
| 343 } | 346 } |
| 344 | 347 |
| 345 Function _onDir; | 348 Function _onDir; |
| 346 Function _onFile; | 349 Function _onFile; |
| 347 Function _onDone; | 350 Function _onDone; |
| 348 Function _onError; | 351 Function _onError; |
| 349 } | 352 } |
| OLD | NEW |