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

Unified Diff: sdk/lib/io/directory_impl.dart

Issue 11759007: Fix Directory.create(recursive: true) for non-existing paths. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 12 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/io/regress_7679_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/directory_impl.dart
diff --git a/sdk/lib/io/directory_impl.dart b/sdk/lib/io/directory_impl.dart
index d96151f329d0144cf7a9923eb543d4a712ee68dc..d3c6a1406ecb24b64cf4f0990d258d8a6a676c13 100644
--- a/sdk/lib/io/directory_impl.dart
+++ b/sdk/lib/io/directory_impl.dart
@@ -52,22 +52,25 @@ class _Directory implements Directory {
return (result == 1);
}
+ // Compute the index of the first directory in the list that exists. If
+ // none of the directories exist dirsToCreate.length is returned.
Future<int> _computeExistingIndex(List dirsToCreate) {
var future;
+ var notFound = dirsToCreate.length;
for (var i = 0; i < dirsToCreate.length; i++) {
if (future == null) {
- future = dirsToCreate[i].exists().transform((e) => e ? i : -1);
+ future = dirsToCreate[i].exists().transform((e) => e ? i : notFound);
} else {
future = future.chain((index) {
- if (index != -1) {
+ if (index != notFound) {
return new Future.immediate(index);
}
- return dirsToCreate[i].exists().transform((e) => e ? i : -1);
+ return dirsToCreate[i].exists().transform((e) => e ? i : notFound);
});
}
}
if (future == null) {
- return new Future.immediate(-1);
+ return new Future.immediate(notFound);
} else {
return future;
}
@@ -85,6 +88,8 @@ class _Directory implements Directory {
path = path.directoryPath;
}
return _computeExistingIndex(dirsToCreate).chain((index) {
+ // If none of the directories already exist we need to create them all.
+ if (index == -1) index = dirsToCreate.length;
Søren Gjesse 2013/01/03 15:11:13 I can't figure out how the _computeExistingIndex c
Mads Ager (google) 2013/01/03 16:04:16 D'oh! That was what it used to do, so this was my
var future;
for (var i = index - 1; i >= 0 ; i--) {
if (future == null) {
« no previous file with comments | « no previous file | tests/standalone/io/regress_7679_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698