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

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

Issue 11416197: Support Windows share paths in the Path class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | sdk/lib/io/path.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 85968f16b6f291410784452f017161b3e6a56604..ecf7959ac28b1e92eb6099c52b18ff9bd462329b 100644
--- a/sdk/lib/io/directory_impl.dart
+++ b/sdk/lib/io/directory_impl.dart
@@ -51,27 +51,55 @@ class _Directory implements Directory {
return (result == 1);
}
+ Future<int> _computeExistingIndex(List dirsToCreate) {
+ var future;
+ for (var i = 0; i < dirsToCreate.length; i++) {
+ if (future == null) {
+ future = dirsToCreate[i].exists().transform((e) => e ? i : -1);
+ } else {
+ future = future.chain((index) {
+ if (index != -1) {
+ return new Future.immediate(index);
+ }
+ return dirsToCreate[i].exists().transform((e) => e ? i : -1);
+ });
+ }
+ }
+ if (future == null) {
+ return new Future.immedidate(-1);
+ } else {
+ return future;
+ }
+ }
+
Future<Directory> createRecursively() {
if (_path is !String) {
throw new ArgumentError();
}
var path = new Path.fromNative(_path);
- var current = new Path(path.isAbsolute ? '/' : '');
- var future = null;
- for (var segment in path.segments()) {
- var next = current.append(segment);
+ var dirsToCreate = [];
+ var terminator = path.isAbsolute ? '/' : '';
+ while (path.toString() != terminator) {
+ dirsToCreate.add(new Directory.fromPath(path));
+ path = path.directoryPath;
+ }
+ return _computeExistingIndex(dirsToCreate).chain((index) {
+ var future;
+ for (var i = index - 1; i >= 0 ; i--) {
+ if (future == null) {
+ future = dirsToCreate[i].create();
+ } else {
+ future = future.chain((_) {
+ return dirsToCreate[i].create();
+ });
+ }
+ }
if (future == null) {
- future = new Directory.fromPath(current).create();
+ return new Future.immediate(this);
} else {
- future = future.chain((_) => new Directory.fromPath(next).create());
+ return future.transform((_) => this);
}
- current = next;
- }
- if (future == null) {
- return new Future.immediate(this);
- } else {
- return future.transform((result) => this);
- }
+ });
}
Future<Directory> create({recursive: false}) {
@@ -90,10 +118,16 @@ class _Directory implements Directory {
void createRecursivelySync() {
var path = new Path.fromNative(_path);
- var current = new Path(path.isAbsolute ? '/' : '');
- for (var segment in path.segments()) {
- current = current.append(segment);
- new Directory.fromPath(current).createSync();
+ var dirsToCreate = [];
+ var terminator = path.isAbsolute ? '/' : '';
+ while (path.toString() != terminator) {
+ var dir = new Directory.fromPath(path);
+ if (dir.existsSync()) break;
+ dirsToCreate.add(dir);
+ path = path.directoryPath;
+ }
+ for (var i = dirsToCreate.length - 1; i >= 0; i--) {
+ dirsToCreate[i].createSync();
}
}
« no previous file with comments | « no previous file | sdk/lib/io/path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698