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

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

Issue 52363002: dart:io | Add 'recursive' flag to File.create and Link.create. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Indentation. Created 7 years, 2 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 | sdk/lib/io/file.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 10b60680019144325834a57456f21dd72aaaffbe..9cbd1b9661d198a52976c78b435e1b8df6e60e04 100644
--- a/sdk/lib/io/directory_impl.dart
+++ b/sdk/lib/io/directory_impl.dart
@@ -90,57 +90,35 @@ class _Directory extends FileSystemEntity implements Directory {
}
}
- Future<Directory> createRecursively() {
- var dirsToCreate = [];
- var dir = this;
- while (dir.path != dir.parent.path) {
- dirsToCreate.add(dir);
- dir = dir.parent;
- }
- return _computeExistingIndex(dirsToCreate).then((index) {
- var future;
- for (var i = index - 1; i >= 0 ; i--) {
- if (future == null) {
- future = dirsToCreate[i].create();
- } else {
- future = future.then((_) {
- return dirsToCreate[i].create();
+ Future<Directory> create({bool recursive: false}) {
+ if (recursive) {
+ return exists().then((exists) {
+ if (exists) return this;
+ if (path != parent.path) {
+ return parent.create(recursive: true).then((_) {
+ return create();
});
+ } else {
+ return create();
}
- }
- if (future == null) {
- return new Future.value(this);
- } else {
- return future.then((_) => this);
- }
- });
- }
-
- Future<Directory> create({bool recursive: false}) {
- if (recursive) return createRecursively();
- return _IOService.dispatch(_DIRECTORY_CREATE, [path]).then((response) {
- if (_isErrorResponse(response)) {
- throw _exceptionOrErrorFromResponse(response, "Creation failed");
- }
- return this;
- });
- }
-
- void createRecursivelySync() {
- var dir = this;
- var dirsToCreate = [];
- while (dir.path != dir.parent.path) {
- if (dir.existsSync()) break;
- dirsToCreate.add(dir);
- dir = dir.parent;
- }
- for (var i = dirsToCreate.length - 1; i >= 0; i--) {
- dirsToCreate[i].createSync();
+ });
+ } else {
+ return _IOService.dispatch(_DIRECTORY_CREATE, [path]).then((response) {
+ if (_isErrorResponse(response)) {
+ throw _exceptionOrErrorFromResponse(response, "Creation failed");
+ }
+ return this;
+ });
}
}
void createSync({bool recursive: false}) {
- if (recursive) return createRecursivelySync();
+ if (recursive) {
+ if (existsSync()) return;
+ if (path != parent.path) {
+ parent.createSync(recursive: true);
+ }
+ }
var result = _create(path);
if (result is OSError) {
throw new FileSystemException("Creation failed", path, result);
« no previous file with comments | « no previous file | sdk/lib/io/file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698