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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/io/file.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(String this.path) { 10 _Directory(String this.path) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 }); 83 });
84 } 84 }
85 } 85 }
86 if (future == null) { 86 if (future == null) {
87 return new Future.value(notFound); 87 return new Future.value(notFound);
88 } else { 88 } else {
89 return future; 89 return future;
90 } 90 }
91 } 91 }
92 92
93 Future<Directory> createRecursively() { 93 Future<Directory> create({bool recursive: false}) {
94 var dirsToCreate = []; 94 if (recursive) {
95 var dir = this; 95 return exists().then((exists) {
96 while (dir.path != dir.parent.path) { 96 if (exists) return this;
97 dirsToCreate.add(dir); 97 if (path != parent.path) {
98 dir = dir.parent; 98 return parent.create(recursive: true).then((_) {
99 } 99 return create();
100 return _computeExistingIndex(dirsToCreate).then((index) { 100 });
101 var future;
102 for (var i = index - 1; i >= 0 ; i--) {
103 if (future == null) {
104 future = dirsToCreate[i].create();
105 } else { 101 } else {
106 future = future.then((_) { 102 return create();
107 return dirsToCreate[i].create();
108 });
109 } 103 }
110 } 104 });
111 if (future == null) { 105 } else {
112 return new Future.value(this); 106 return _IOService.dispatch(_DIRECTORY_CREATE, [path]).then((response) {
113 } else { 107 if (_isErrorResponse(response)) {
114 return future.then((_) => this); 108 throw _exceptionOrErrorFromResponse(response, "Creation failed");
115 } 109 }
116 }); 110 return this;
117 } 111 });
118
119 Future<Directory> create({bool recursive: false}) {
120 if (recursive) return createRecursively();
121 return _IOService.dispatch(_DIRECTORY_CREATE, [path]).then((response) {
122 if (_isErrorResponse(response)) {
123 throw _exceptionOrErrorFromResponse(response, "Creation failed");
124 }
125 return this;
126 });
127 }
128
129 void createRecursivelySync() {
130 var dir = this;
131 var dirsToCreate = [];
132 while (dir.path != dir.parent.path) {
133 if (dir.existsSync()) break;
134 dirsToCreate.add(dir);
135 dir = dir.parent;
136 }
137 for (var i = dirsToCreate.length - 1; i >= 0; i--) {
138 dirsToCreate[i].createSync();
139 } 112 }
140 } 113 }
141 114
142 void createSync({bool recursive: false}) { 115 void createSync({bool recursive: false}) {
143 if (recursive) return createRecursivelySync(); 116 if (recursive) {
117 if (existsSync()) return;
118 if (path != parent.path) {
119 parent.createSync(recursive: true);
120 }
121 }
144 var result = _create(path); 122 var result = _create(path);
145 if (result is OSError) { 123 if (result is OSError) {
146 throw new FileSystemException("Creation failed", path, result); 124 throw new FileSystemException("Creation failed", path, result);
147 } 125 }
148 } 126 }
149 127
150 static Directory get systemTemp => new Directory(_systemTemp()); 128 static Directory get systemTemp => new Directory(_systemTemp());
151 129
152 Future<Directory> createTemp([String prefix]) { 130 Future<Directory> createTemp([String prefix]) {
153 if (prefix == null) prefix = ''; 131 if (prefix == null) prefix = '';
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 controller.addError( 380 controller.addError(
403 new FileSystemException("Directory listing failed", 381 new FileSystemException("Directory listing failed",
404 errorPath, 382 errorPath,
405 err)); 383 err));
406 } else { 384 } else {
407 controller.addError( 385 controller.addError(
408 new FileSystemException("Internal error")); 386 new FileSystemException("Internal error"));
409 } 387 }
410 } 388 }
411 } 389 }
OLDNEW
« 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